Jump to content

Recommended Posts

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 ;

Link to comment
https://forums.phpfreaks.com/topic/161159-session-question/
Share on other sites

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 ;)

Link to comment
https://forums.phpfreaks.com/topic/161159-session-question/#findComment-850442
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/161159-session-question/#findComment-850538
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.