Ifaiden Posted September 13, 2011 Share Posted September 13, 2011 Hi! I'm working on a simple e-commerce script. I have some $_SESSION variables that is defined and works fine while surfing on the site. But when I close the browser and reenter the site, all the session-variables are not defined (unset?), until i click on a link on the site. Weird behavior... please help! /I Quote Link to comment https://forums.phpfreaks.com/topic/247049-session-vars-disappears/ Share on other sites More sharing options...
9mileshq Posted September 13, 2011 Share Posted September 13, 2011 I'm assuming you session_start(); at the top of the page you are re-entering? Quote Link to comment https://forums.phpfreaks.com/topic/247049-session-vars-disappears/#findComment-1268716 Share on other sites More sharing options...
Ifaiden Posted September 13, 2011 Author Share Posted September 13, 2011 Yes, I am. Is this the wrong way to use it? (correction: how do I make it work? ) Quote Link to comment https://forums.phpfreaks.com/topic/247049-session-vars-disappears/#findComment-1268717 Share on other sites More sharing options...
KevinM1 Posted September 13, 2011 Share Posted September 13, 2011 Sessions usually only exist for as long as the user doesn't close their browser. If you need the info to last even after a user closes the browser, you can modify how long the session cookie lives: http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime Quote Link to comment https://forums.phpfreaks.com/topic/247049-session-vars-disappears/#findComment-1268718 Share on other sites More sharing options...
Ifaiden Posted September 13, 2011 Author Share Posted September 13, 2011 Ok, thanks for the quick answer. If I don't want to use cookies, can I instead place the file temporarily in a database (mysql?) and have like a timeout that removes and updates the database? Is this more optimized than cookies? Quote Link to comment https://forums.phpfreaks.com/topic/247049-session-vars-disappears/#findComment-1268719 Share on other sites More sharing options...
Ifaiden Posted September 13, 2011 Author Share Posted September 13, 2011 Sessions usually only exist for as long as the user doesn't close their browser. If you need the info to last even after a user closes the browser, you can modify how long the session cookie lives: http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime From the link: "session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." Defaults to 0.". It doesn't state anything about "session stays active even after the browser has been closed" Quote Link to comment https://forums.phpfreaks.com/topic/247049-session-vars-disappears/#findComment-1268723 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.