Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set session expiry time

Tags:

php

session

How can I set the session expiry time to 10 minutes for the whole of my site? I cannot use the php.ini as its on shared hosting.

Is there a global method I could use?

like image 280
Adamski Avatar asked Feb 25 '23 02:02

Adamski


1 Answers

I don't think so.

You can save the timestamp of the last refresh of your website into a session and compare it with the current time on the next reload.

if(isset($_SESSION['expiretime'])) {
    if($_SESSION['expiretime'] < time()) {
        //logged out
    }
    else {
        $_SESSION['expiretime'] = time() + 600;
    }
}
//maybe add some login procedures and than execute the following line
$_SESSION['expiretime'] = time() + 600;
like image 60
lszrh Avatar answered Mar 06 '23 20:03

lszrh