I am trying to output a simple link.
This works great:
$url = 'http://www.google.com';
echo $url;
This doesn’t work great:
$url = 'http://www.google.com';
echo urlencode($url);
The second example tacks on “?SID=xxx” to the end of the URL for some reason. How do I prevent this from happening?
Note: The code to generate the URL has been changed to protect the innocent.
Don’t use urlencode() to encode URL, you will end up an URL like this,
To PHP, this looks like a relative URL so it appends SID when cookie is missing.
urlencode() should be used to encode query string parameters but not the URL itself.