Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 03:56 AM
alain dhaene
Guest
 
Posts: n/a
Default 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





  #2  
Old July 17th, 2005, 03:56 AM
Jerry
Guest
 
Posts: n/a
Default Re: redirect

Use double quotes instead.
" instead of ' in your header argument.


On Wed, 4 Feb 2004 11:24:53 +0100, "alain dhaene"
<a.dhaene@instruct.be> wrote:
[color=blue]
>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
>[/color]

  #3  
Old July 17th, 2005, 03:56 AM
Pedro Graca
Guest
 
Posts: n/a
Default Re: redirect

alain dhaene wrote:[color=blue]
> 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[/color]

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 =--
  #4  
Old July 17th, 2005, 03:57 AM
Matthias Esken
Guest
 
Posts: n/a
Default Re: redirect

Pedro Graca <hexkid@hotpop.com> schrieb:
[color=blue]
> Better yet is to use urlencode() for the $order_nummer:
>
> header('Location: xmlorderon.php?order_id=' . urlencode($order_nummer));[/color]

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
  #5  
Old July 17th, 2005, 03:57 AM
Pedro Graca
Guest
 
Posts: n/a
Default Re: redirect

Matthias Esken wrote:[color=blue]
> 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));[/color]

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 =--
  #6  
Old July 17th, 2005, 03:57 AM
Pedro Graca
Guest
 
Posts: n/a
Default Re: redirect

Pedro Graca wrote:[color=blue]
> Right. Thank you for the correction.[/color]

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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.