PHP urlencode() tacking on ?SID=xxx ... Why?
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. H开发者_开发知识库ow 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,
http%3A%2F%2Fwww.google.com
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.
This is not urlencode()
s fault, it's PHP's automatic link rewriting that adds the session ID through a GET variable in absence of a session cookie.
I'm afraid this is necessary to persist sessions on the client side if they have cookies disabled.
The setting to do this automatically is session.use_trans_sid
. More info here.
精彩评论