-
Jun 24th, 2007, 04:31 AM
#1
Thread Starter
Frenzied Member
Object stored in session not retained
I'm storing a shopping cart object in a session, it works fine when navigating pages in the application, the object is being retained intact, however if I close the browser and go back to a page it doesn't retain. Either the items member of the object is being cleared, or the session is being destroyed. I've used sessions before storing simple strings for a login system, it allowed me to close the browser and return to the page still logged in, thats what I'm trying to achieve.
Here's how I'm storing the object in the session:
Code:
<?
require_once("clsCart.php");
session_start();
if(!isset($_SESSION['cart']))
{
//cart doesn't exist
$_SESSION['cart'] = new cart;
}
Edit: Sometimes it is working, when I close and open it back up but sometimes not. I'm not leaving any length of time between closing and opening.
Cheers all
Last edited by the182guy; Jun 24th, 2007 at 04:36 AM.
Chris
-
Jun 24th, 2007, 04:38 AM
#2
Re: Object stored in session not retained
The default timeout for a session cookie is zero, which means it expires when the browser is closed. If you wish it to persist past this point you need to either alter the expiration time manually, or set your own auto-login cookie. The second option is preferable, but requires that you, at some point, commit data to a database rather than relying on the session being available.
Most sophisticated shopping cart/order tracking systems store carts and orders in a database so that the user can log in and retrieve them at a later date. This is what I suggest you do.
-
Jun 24th, 2007, 05:39 AM
#3
Thread Starter
Frenzied Member
Re: Object stored in session not retained
Cheers. I'll just use the timeout of 20mins or so. Yeah I was going to do that in the first place, store it in a db against the users login, but that means people will have to sign up and arse around validating emails just to buy a few items or shop around. Using sessions allows people to visit the site, add items to a cart and checkout.
-
Jun 24th, 2007, 07:09 AM
#4
Re: Object stored in session not retained
You can use ini_set to set the session.cookie_lifetime directive within your scripts. But i wouldn't really recommend this. A session, as the name implies is something temporary.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|