Page 1 of 1

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

Posted: Fri Aug 22, 2008 4:24 am
by rfeio
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:


/* 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!

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

Posted: Fri Aug 22, 2008 7:17 am
by rfeio
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! :-)

Cheers!