Page 1 of 1
how to echo php variable in a header direct
Posted: Wed Feb 04, 2009 2:19 pm
by tate
Hi
if I have a variable
say
$sausage = something
How do I put that variable in the header direct
i.e
header("Location:
http://mysite.com/?tid=$sausage");
does not work.
How do I do it???
Thanks.
Tate.
Re: how to echo php variable in a header direct
Posted: Wed Feb 04, 2009 2:54 pm
by John Cartwright
Variables are parsed within double quotes, so it actually is working. I would suspect the value of $sausage is not what you expect.
Alternatively, you can escape the quotes or use single quotes.
Code: Select all
header("Location: http://mysite.com/?tid=$sausage");
header("Location: http://mysite.com/?tid=". $sausage);
header('Location: http://mysite.com/?tid='. $sausage);
Are all perfectly legit. Try var_dump($sausage); before the header call to see what the value of $sausage is.
Re: how to echo php variable in a header direct
Posted: Wed Feb 04, 2009 4:34 pm
by tate
Thats great!
It works!! Thanks!
If I wanted it to open a new webpage, so my site site still remains, how do I do that???
Re: how to echo php variable in a header direct
Posted: Wed Feb 04, 2009 9:50 pm
by John Cartwright
tate wrote:Thats great!
It works!! Thanks!
If I wanted it to open a new webpage, so my site site still remains, how do I do that???
You will have to use html/javascript. A header redirect has no control of the client.