470,815 Members | 3,017 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

redirect

Hi,

What's wrong with that?

I have a variable

$order_nummer = "C.45";

Then I redirect to

header('Location: xmlorderon.php?order_id=$order_nummer');

but I my location bar I see:

http://localhost/pcGebruik/files/xmlorderon.php?order_id=$order_nummer
thx
Alain
Jul 17 '05 #1
5 2614
Use double quotes instead.
" instead of ' in your header argument.
On Wed, 4 Feb 2004 11:24:53 +0100, "alain dhaene"
<a.******@instruct.be> wrote:
Hi,

What's wrong with that?

I have a variable

$order_nummer = "C.45";

Then I redirect to

header('Location: xmlorderon.php?order_id=$order_nummer');

but I my location bar I see:

http://localhost/pcGebruik/files/xmlorderon.php?order_id=$order_nummer
thx
Alain


Jul 17 '05 #2
alain dhaene wrote:
I have a variable

$order_nummer = "C.45";

Then I redirect to

header('Location: xmlorderon.php?order_id=$order_nummer');

but I my location bar I see:

http://localhost/pcGebruik/files/xmlorderon.php?order_id=$order_nummer


The contents of single quotes are taken literally (with two exceptions).

echo 'the variable a holds $a'; // taken literally
echo 'it\'s a exception'; // the \' is taken as a single '
echo 'the other exception is \\ a single backslash';
So to have your header() do what you want either use double quotes
(which interpolate much more than single quotes) or concatenate the
contents of $order_nummer to the rest of the URL:

header('Location: xmlorderon.php?order_id=' . $order_nummer);

Better yet is to use urlencode() for the $order_nummer:

header('Location: xmlorderon.php?order_id=' . urlencode($order_nummer));
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3
Pedro Graca <he****@hotpop.com> schrieb:
Better yet is to use urlencode() for the $order_nummer:

header('Location: xmlorderon.php?order_id=' . urlencode($order_nummer));


And even better would be the use of a valid syntax for the location.

header('Location: http://www.example.com/xmlorderon.php?order_id=' .
urlencode($order_nummer));

According to http://www.php.net/manual/en/function.header.php HTTP/1.1
requires an absolute URI as argument to Location: including the scheme,
hostname and absolute path, but some clients accept relative URIs. So
with the short version it might work on some clients and fail on others
and that's not what you want. :-) Use the correct version and it will
run anywhere.

Regards,
Matthias
Jul 17 '05 #4
Matthias Esken wrote:
And even better would be the use of a valid syntax for the location.

header('Location: http://www.example.com/xmlorderon.php?order_id=' .
urlencode($order_nummer));


Right. Thank you for the correction.

The W3C (World Wide Web Consortium) says the same thing about the
Location: header:
http://www.w3.org/Protocols/rfc2616/....html#sec14.30
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #5
Pedro Graca wrote:
Right. Thank you for the correction.


Where it is written "correction", please read "revision and update"
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Bob Garbados | last post: by
3 posts views Thread by Paul | last post: by
7 posts views Thread by Donna Hawkins | last post: by
1 post views Thread by Peter Kirk | last post: by
2 posts views Thread by Mark Dengler | last post: by
3 posts views Thread by Justin | last post: by
6 posts views Thread by Sam | last post: by
6 posts views Thread by Peter Row | last post: by
10 posts views Thread by Eirik Eldorsen | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.