Reputation: 8303
I'm using a PHP session for a website to display a disclaimer page when the user first logs on to the site. After the user's browsing session, or when they close their browser, the session should be destroyed automatically. It is working properly in all browsers except for Chrome. After some research, I found this which led to this. If it is indeed a bug with Chrome, how can I work around it?
Upvotes: 2
Views: 2017
Reputation: 281
Instead of relying on the browser to cancel the cookie, set it to expire fairly quickly, and keep the session "alive" by renewing the cookie on subsequent page requests.
<?php
session_set_cookie( 60*15 );
session_start();
This example sets the cookie to expire after 15 minutes (you might set a different expiry, depending on how often you expect your users to send page requests: or, you could set it for only a minute or two, and get a fresh cookie via XHR just a little more frequently than that). This won't make Chrome delete the cookie, but you at least know it won't be floating around indefinitely.
Upvotes: 0
Reputation: 3998
Session cookies are suppose to be deleted if browser being closed and they are sent without expire time.
You can define session_cache_expire before start session first time:
session_cache_expire(60); // expires after 60 mins
And then do session_start();...
Upvotes: 3