Jump to content

Archived

This topic is now archived and is closed to further replies.

Darkness Soul

Session life time

Recommended Posts

yo, :D

Guys, I've been look for a function to extend my session life time, unhappy, I don't found.

By default, a session have 30 minutes as life time, but I need 40 minutes.. :-[

Thank you,

D.Soul

Share this post


Link to post
Share on other sites
[url=http://php.net/ini_set]ini_set[/url] should help you out.

Share this post


Link to post
Share on other sites
so, is that correct?

[code]// before start, in all files
ini_set ( "session.gc_maxlifetime" , "2400" ) ;
session_start () ;[/code]

or should I use "session.cache_expire" ?

Share this post


Link to post
Share on other sites
[quote]
session.gc_maxlifetime integer

session.gc_maxlifetime specifies the number of seconds after which data will be seen as 'garbage' and cleaned up. Garbage collection occurs during session start.

Note: If different scripts have different values of session.gc_maxlifetime but share the same place for storing the session data then the script with the minimum value will be cleaning the data. In this case, use this directive together with session.save_path.
[/quote]

The manual has all the answers ;)

In other words, yes the maximum time for session data to remain in storage is set by session.gc_maxlifetime.  However, when the browser is closed or cookies cleared, the session may expire clientside.  To keep the session persistent regardless of this you will need to set the sessionid into a cookie and as long as the client maintains that cookie, the session will be kept - up to the maximum lifetime (which is updated everytime the session is used). 

Hope this helps,

Dest

Share this post


Link to post
Share on other sites
Thank you Dest, but still "broke"..

I've write this code at main.php page with the time set to 5 seconds, so I've tried to wait and reload. It was with the session data yet.. =(

My login system use a session variable to hold the auth permission, so, the main redirect to the index when it "burn away"..

:'( I'm without options.. another way?

D.Soul

Share this post


Link to post
Share on other sites
GC = Garbage Collection and isn't run every time.  It's set by the divisor etc.

You could set it manually within your code like a tracking system.  I believe there's a tutorial on phpfreaks that shows how to track users online time.  You could make it so that if they went over that time period, it changed the session value for auth.

Dest

Share this post


Link to post
Share on other sites
Yo,

I've tested it, it's kill the session for some reason, but not like I wanna =(..

[code]ini_set ( 'session.use_cookies' , true ) ;
ini_set ( 'session.name' , 'the_sess__uniq_name' ) ;
ini_set ( 'session.auto_start' , false ) ;
ini_set ( 'session.gc_maxlifetime' , 5 ) ;  // in seconds, like: N + time()
ini_set ( 'session.cookie_lifetime' , 5 ) ;  // in seconds, like: N + time()
ini_set ( 'session.serialize_handler' , 'php' ) ;
ini_set ( 'session.gc_probability' , 1 ) ;
session_start() ;[/code]

D.Soul

Share this post


Link to post
Share on other sites

×

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.