Session automatically expires after a while in php

I am developing a simple php site named: http://www.dopanchat.com

On this site I used a session to develop a login system, everything works fine, but after a while (for example 1 hour) the session expires automatically and the user is logged out of my site.

I don't know if it's a server problem or something else.

please help me to solve this problem, you can check here: http://www.dopanchat.com

+3


source to share


3 answers


Session timeout extension is an approach, but I won't recommend it too much :)

Instead, your application can detect user activity and update the session expiration time accordingly.



In the end, it doesn't matter what session timeout at some point the user will lose authentication due to the expired session.

Basically, the expiration counter always starts after the last user action, not the moment they logged in.

+2


source


you can extend the session end time by configuring the php.ini

file as follows

session.gc_maxlifetime=86400 //1 day
session.gc_divisor=5000
session.gc_probability=1

      



gc_divisor and gc_probability are responsible for cleaning up expired session files, with the previous config session being valid for 1 day

0


source


Try the following:

// Time in secondes before the session expires
ini_set('session.gc_maxlifetime', 3600);

// Time in secondes before the ID session in the cookie expires
session_set_cookie_params(3600);

// Start session
session_start();

      

If you think it will work. Tell me if it works!

(Sorry for my bad english: D)

0


source







All Articles