Jump to content

? symbol being escaped when using header(Location: ...)


rfeio

Recommended Posts

Hi,

 

I'm trying to redirect the one of my page to another site where I need to pass some values to.

 

An example of the code I'm using:

 

$url = 'http://'.$site.'?form='.$form;

 

 

when I echo the variable $url I get:

 

http://www.website.com?form=123 

 

 

 

when I try to do the redirection using the header function:

 

header("Location: $url");

 

the result is:

 

http://www.website.com/?form=123 

 

which doesn't redirect me the correct way.

 

How can I solve this?

 

Thanks!

 

Rfeio

Here's the code:

 

/* Note: $picture value is calculated before and assumes a numeric value */

 

$url = "http://www.sanzanne.com/showpicture.php";

 

$redirect = $url.'?picture='.$picture;

 

header("Location: $redirect");

 

die;

 

 

If I do an "echo $redirect;" the result is: http://www.sanzanne.com/showpicture.php?picture=19

 

However, when the header comes in to play the result is: http://www.sanzanne.com/showpicture.php/?picture=19

 

As you can see instead of having a simple ? I'm getting a /?

 

This means that the picture parameter is ignored and no value is passed to the page showpicture.php.

 

How can I solve this?

 

Cheers!

I found the problem. 

 

On my tests to try to identify the problem, I was passing the correct url to $url and afterwards I was echoing it. I never did test the header this way. For the header I only tested it with MySQL and that was the problem. The MySQL table field that $url was picking its value from had no domain indication

 

So istead of $url having "http://www.sanzanne.com/showpicture.php" it only had "http://showpicture.php".

 

So when I tried to redirect using the header function, the function interpreted "showpicture.php" as being the domain, and therefore had to add the / before the ? causing:

 

http://showpicture.php/?picture=19

 

when giving the correct value to the table field it worked as expected; the end result was:

 

http://www.sanzanne.com/showpicture.php?picture=19

 

 

I feel so stupid! :-)

 

Thanks for all the help guys!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.