dreamwest Posted June 6, 2009 Share Posted June 6, 2009 OK ive sucessfully transfered all my cookie code to sessions, but how long will they last by default?, i want to make them last about 6 months if possible, heres what ive done if (!isset($_SESSION['cinema'])){ $_SESSION['cinema']='off'; //how long will this last } Also i cant seem to echo the session id if (!isset($_SESSION['cinema'])){ $_SESSION['cinema']='off'; //how long will this last } echo SID ; Quote Link to comment https://forums.phpfreaks.com/topic/161159-session-question/ Share on other sites More sharing options...
ToonMariner Posted June 6, 2009 Share Posted June 6, 2009 sessions default to timeout after 20 mins normally. You should NOT use them for storing data that you require to have longevity - its the client side cookie you need to use for that purpose. Quote Link to comment https://forums.phpfreaks.com/topic/161159-session-question/#findComment-850441 Share on other sites More sharing options...
Daniel0 Posted June 6, 2009 Share Posted June 6, 2009 See: session_set_cookie_params in the manual, and "Sessions and cookies: Adding state to a stateless protocol" on this site. sessions default to timeout after 20 mins normally. They default to last until the UA is closed. Only if you restart your browser every 20 minutes are you correct Quote Link to comment https://forums.phpfreaks.com/topic/161159-session-question/#findComment-850442 Share on other sites More sharing options...
PFMaBiSmAd Posted June 6, 2009 Share Posted June 6, 2009 A session is intended to be last for 1 browser session, which is where the name comes from. By default it ends when the browser closes because the session cookie has a default lifetime of zero. To extend a session beyond this, you must both extend the session cookie lifetime and extend the session.gc_maxlifetime by the same amount (because a session consists of two parts, the session id from the client and the session data on the server.) If your session data files are in the default tmp location on a shared web server, you must also change the session.save_path to be to a private folder within your account's folder tree so that your session.gc_maxlifetime setting will apply to your session data files (when in the shared tmp location, the shortest session.gc_maxlifetime setting of all the accounts wins.) You must set all the mentioned values before every session_start() statement. Globally putting them into the master php.ini is best, but a .htaccess file (when php is running as an Apache module), a local php.ini (when php is running as a CGI application), or even in your script is OK. If you are doing this for something like a "remember me" login function, it is much simpler to use a cookie that holds a unique identifier to identify your visitor. Quote Link to comment https://forums.phpfreaks.com/topic/161159-session-question/#findComment-850538 Share on other sites More sharing options...
.josh Posted June 6, 2009 Share Posted June 6, 2009 or if this is not a "remember me" value, you would store the data in a flatfile or database, if you're looking for a server-side solution. Quote Link to comment https://forums.phpfreaks.com/topic/161159-session-question/#findComment-850558 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.