tags:

views:

33

answers:

2

I'm working with sessions for the first time and why does the variable $session_life always = 0?

$_SESSION['time'] = time();
$inactive = 30;
$session_life = time() - $_SESSION['time'];
A: 

If those expressions happen one after the other what you're doing is essentially:

time() - time();

which is likely to return 0.

karim79
That's what it was! I guess what i wanted to do was set $_session['time'] after a block of code that i'm calling and not before it.
Catfish
No, you would set session time at the beginning, ex. after successful login, and check it before you handle any other requests.
Nael El Shawwa
+5  A: 

time() returns the current timestamp in seconds - less than a second has passed between the first and third lines. Try using microtime() instead:

http://us2.php.net/manual/en/function.microtime.php

pygorex1