Jump to content

What is the default $_SESSION expiry lifetime?


colap

Recommended Posts

Hi,

 

What is the default $_SESSION expiry lifetime?

 

I have used $_SESSION variables but it is not ending it's lifetime. It looks like it is infinite lifetime, but i didn't configure anything. Where to set session's lifetime, In php.ini files? Or do i have to use ini_set() function at top?

 

Is session_start() written at top of php scripts or ini_set() function?

 

Any help will be highly appreciated.

 

Thanks in advance.

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Yes, default is set to not expire

 

You can set your own session settings using the php.ini or using ini_set. The following page outlines all the runtime settings for sessions

http://php.net/manual/en/session.configuration.php

 

You will need do this before calling session_start()

 

 

Is session_start() written at top of php scripts or ini_set() function?

session_start() is a function, which you must call at the of all pages that uses sessions.

Edited by Ch0cu3r
Link to comment
Share on other sites

Sessions are not infinite by default, and there are actually two lifetime settings: The session.cookie_lifetime directive defines how long the session cookie is valid. It's typically set to “0”, which means the cookie is deleted when the user closes the browser. And the session.gc_maxlifetime directive defines how long the session file is considered valid. Note that expired files aren't cleared immediately. The session garbage collector which deletes the files is only executed with a certain probability, so the file may still exist for a while.

 

Both settings together more or less determine the lifetime of the session.

Link to comment
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.