My PHP web app currently has its session cookie domain set to example.com
. I'd like to change it to .example.com
. For new visitors, ini_set('session.cookie_domain', '.example.com')
works. For visitors who already have the PHPSESSID cookie before this change is made, the domain remains at the old value. How can I change the domain on the session cookie without asking current users to delete their cookies?
The only possibility I can come up with is to set the cookie to expire in the past and then redirect to get a new cookie. But I can't know which visitors have the cookie domain set incorrectly.
Set a new session_name()
before you start the session. That way the name of the cookie changes, and any old cookie will be ignored. Only new cookies will be sent out and work for the session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With