Question

I am serving dynamic image content which is generated by PHP. But for such requests to a .php file, the PHPSESSID cookie is being sent along, which is a waste.

Is it possible to prevent PHP from sending this cookie with requests to a PHP file? Or is it completely necessary for PHP to work?

Thanks for your time!

Was it helpful?

Solution

The browser will send any cookie that applies to a certain path-domain combination. You have no control over that, except using different paths and domains. This is why many sites use static content domains.

OTHER TIPS

This is used by PHP's session functions. If your site doesn't use sessions, then this probably shouldn't be showing up.

Keep in mind that the cookie is sent by the browser and you have no control over its transmission.

you're saying "dont use cookies for sessions, use a phpsessid as a get parameter" php deprecated this for a reason. Cookies will always be sent to the same domain. If you really want to avoid the MINIMAL overhead, resources which dont need cookies should be in a separate domain, thus the cookie wont be sent. IE. static.domain.com for static content. It's not worth the hassle, honestly.

i've searched and this is the only solution i found that worked for me.

Add the following code to your .htaccess file:

RewriteCond %{QUERY_STRING} PHPSESSID=.*$

RewriteRule .* %{REQUEST_URI}? [R=301,L]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top