0

I'm newbie in php and I have a question. So for example I have in session array a variable call game_url:

$_SESSION['game_url'] = $_SERVER['HTTP_REFERER'];

Is it possible to make a $_SESSION['game_url'] = ''; after 2 min after it has set? Any help would be appreciated.

Rasclatt
  • 12,498
  • 3
  • 25
  • 33
TanGio
  • 766
  • 2
  • 12
  • 34
  • 2
    http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes – tesst Jul 23 '15 at 13:21
  • pls show us, what you tried and how you want to use it. Just from the scratch I'd recommand AJAX for that kind of stuff. – DocRattie Jul 23 '15 at 13:21
  • You can store current time in a session and when someone will check this after 2 minute, you just check the time difference and make it empty. – William Francis Gomes Jul 23 '15 at 13:21

1 Answers1

1
if (!isset($_SESSION['game_url']))
{
    $_SESSION['LAST_ACTIVITY'] = time();
    $_SESSION['game_url'] = $_SERVER['HTTP_REFERER'];
}
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 120)) 
{
    unset($_SESSION['game_url']);
    unset($_SESSION['LAST_ACTIVITY']);
}
tesst
  • 149
  • 1
  • 11
  • In theory this works, in practice I would avoid the key "LAST_ACTIVITY" since it does sound like something common enough to be overwritten by a framework/library. – apokryfos Aug 21 '15 at 14:59