expire session when there is no activity in PHP -
i found many tutorials on internet when expire session after limit, after 30 minutes or so, want expire session when there no activity, quoting famous question the solution straight forward:
if (isset($_session['last_activity']) && (time() - $_session['last_activity'] > 1800)) { // last request more 30 minutes ago session_unset(); // unset $_session variable run-time session_destroy(); // destroy session data in storage } $_session['last_activity'] = time(); // update last activity time stamp
but have update $_session['last_activity']
on each request?
the pre-assumed answer yes, have big site containing 200+ php pages , it's hectic update $_session['last_activity']
on each request.
is there other way of doing this? common thing among files 1 config file db connection.
you update $_session['last_activity']
(eg) once per minute session not destroyed after 30 minutes.
if (isset($_session["last_activity"])) { if (time() - $_session["last_activity"] > 1800)) { // last request more 30 minutes ago session_unset(); // unset $_session variable run-time session_destroy(); // destroy session data in storage } else if (time() - $_session["last_activity"] > 60) { $_session["last_activity"] = time(); // update last activity time stamp } }
and easiest way put code in config file since don't think want change 200 php files.
Comments
Post a Comment