Jump to content

encode ampersand in header


cberube09

Recommended Posts

I am trying to encode an ampersand as & within the php header("Location: "); .  This method works fine in normal links in php but in the header it passes to the browser as the encoded form & in the url.  How do I encode an ampersand in the url of a header redirect?

Link to comment
Share on other sites

Right, sorry, that what I meant, I just wrote the wrong thing.

 

This is the code with the url unencoded

header("Location:index.php?content=main&id=$categoryout&title=$titleout");

 

 

When I use anything like & or %26, that is what shows up in the URL when it redirects, not the regular &, so in turn, the page is not found.

Link to comment
Share on other sites

Try:

 

header("Location: index.php?content=main&id=" . urlencode($categoryout) . "&title=" . urlencode($titleout));

 

 

And technically it should be something like:

 

 

header("Location: http://{$_SERVER['HTTP_HOST']}/index.php?content=main&id=" . urlencode($categoryout) . "&title=" . urlencode($titleout));

 

 

Since the HTTP specification says that Location is to specify a full URL, domain included.

Link to comment
Share on other sites

Something like this...

index.php?content=main&id=Government_Policy&title=Hypocritical_Politicians

 

I want to encode the ampersands because that this is required by W3 specification.  Since the ampersand does not mean AND but is an operator in the link, it must be encoded.

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.