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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.