Jump to content

Session Data Automatically Deleted When Browser Closed


son
 Share

Recommended Posts

It won't automatically restart the session, even if it still has the session cookie PHP has already deleted the session data on the server (unless you've set the session expire time way past the default). If it's finding information then you're probably already using a cookie, and it's finding the cookie you set. It doesn't matter if the browser still has the session cookie if it's already been deleted on the server though.

Link to comment
Share on other sites

It won't automatically restart the session, even if it still has the session cookie PHP has already deleted the session data on the server (unless you've set the session expire time way past the default). If it's finding information then you're probably already using a cookie, and it's finding the cookie you set. It doesn't matter if the browser still has the session cookie if it's already been deleted on the server though.
I start each page with:
ob_start();// initialize a sessionsession_start();

and create sessioin data for cart with:

$_SESSION['cart'][$id]['qty'] = $qty2

as an example for quantity of shopping cart and

$_SESSION['user_id'] = $row['user_id'];

for user area. When cart contents get send, session data is unset viaunset($_SESSION['cart']);and when user logs out, session data is unset viaunset($_SESSION['user_id']);I do not use cookies....Son

Link to comment
Share on other sites

If you unset the session then the server should not be restoring any state information. Make sure you aren't seeing a cached copy of the page.
As you are saying it. This might be the problem. SOme time ago had massive issues with cached pages. Even when hard-clearing the cache in Firefox and after even re-starting I still looked at cached pages... Would it be best to insert something at top of php page to prevent caching? What would you do?Son
Link to comment
Share on other sites

You can send some headers if you want to tell the browser not to cache the page: header("Expires: Tue, 03 Jul 2001 06:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache");

Link to comment
Share on other sites

You can send some headers if you want to tell the browser not to cache the page: header("Expires: Tue, 03 Jul 2001 06:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache");
Thanks for feedback...Son
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...