Jump to content

PHP - Cookies & Sessions


Recommended Posts

Hi guys,

I want a PHP Cookie & Session to apply to both the domain and all its subdomains, except one specific subdomain which I never want the same cookies/sessions to apply to.


I have the apply too all sorted, just not the exception.


Any help is much appreciated.

Link to comment
Share on other sites

I assume you are referring to setting the session.cookie_domain setting and the setcookie() domain parameter to be: .yourdomain.com to get it to match all variations of yourdomain.com


You would need to use a different session_name for that one sub-domain (let all the others use the default session_name.) This would cause a different session id cookie name to be used for that one sub-domain.


As far as regular cookies, to cause that one sub-domain to ignore the other cookies and only use the ones intended for it, the only thing that comes to mind would be to create unique cookie names (similar to what using a different session name does.) Setup a defined constant that you prepend to the cookie name. You would set this defined constant to a unique value (perhaps the sub-domain name itself) that would create a unique set of cookie names just for that sub-domain. All the setcookie() and $_COOKIE references would use that defined constant when forming the name of the cookie to set or reference.


Link to comment
Share on other sites

I have the cookie/session setting to




which is great, but I need it to be


".mydomain.com" except "exception.mydomain.com" but it would still apply to mydomain.com and all its other subdomains.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

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