PHP: User timeout using timestamp?

Note: Every time file is ran then timestamp in database is set to time().
lets say i have a sql database where user is stored with username, password, timestamp. What is a code that checks if the timestamp in the database is 15 minutes old and if so on refresh or if user goes to new page calls logout()?
Its just confusing doing the timestamps with seconds, So,
$timeout = time() - 900;
if ($sqlResult['timestamp'] > $timeout) {
logout();
}

is the correct?
CHECK:
After checking your/my code it must be
if ($timestamp < time() - 900) {
logout();
}

NOT $timestamp > time() - 900

Am i correct?
 
Make a function that you can put at the top of each page.

Something like

function checktime() {
$time = mysql_fetch_array(mysql_query("SELECT timestamp FROM table WHERE id = '#'"));
$ts = $time['timestamp'];

if ($ts > (time() - 900)) {
logout();
}

} // End function

That might work. I'm not the greatest with times =P

EDIT: That should be right. 60 Seconds in a minute, 15 minutes = 60*15 = 900.
 
Back
Top