4

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?

Amar
  • 13,202
  • 7
  • 53
  • 71
Adamski
  • 5,769
  • 9
  • 32
  • 32
  • possible duplicate of http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes – kieran Feb 15 '11 at 09:50
  • possible duplicate of [PHP - make session expire after X minutes](http://stackoverflow.com/questions/3770150/php-make-session-expire-after-x-minutes) – KV Prajapati Feb 15 '11 at 09:50

2 Answers2

6

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;
lszrh
  • 1,531
  • 1
  • 19
  • 28
2

Realy tricky subject , you can use the following :

session_set_cookie_params(600);

Witch actualy sets the cookie params , so the cookie expires after 10 min , when the user makes a request the browser whont send the phpsessid cookie so php will issue a new session . The problem is that it whont unset the previous session so the previous session will still be valid .

session_set_cookie_params

Poelinca Dorin
  • 9,577
  • 2
  • 39
  • 43
  • 1
    session_set_cookie_params() expires all the available sessions after given time. but no one wants to destroy all the sessions. what if ppl wnt to expire specific session but not all?? – Rafique Mohammed Mar 04 '14 at 06:32