Time-In and time_out Script using php and mysql
Moderator: General Moderators
Time-In and time_out Script using php and mysql
Can anyone give me an idea on how to create a time-In and time-Out using php and mysql or can anyone give me an idea.
- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: Time-In and time_out Script using php and mysql
This code (in PHP) will get you a timestamp:
$_SESSION['timestamp'] = mktime();
Here, the timestamp is being saved as a session value so I can check it later on (to expire a session) but you can assign it to a normal variable. If you want to record it in your DB, create a field that's assigned to the 'timestamp' setting.
If by 'time out' you want a script that tests when a user last did anything on the site (and log them out if their session has expired) you could use this:
To see this in action, you need to create the $_SESSION['timestamp'] in one script, then put the second set of code in a different script and keep reloading it to check when the session has expired.
HTH,
Mecha Godzilla
$_SESSION['timestamp'] = mktime();
Here, the timestamp is being saved as a session value so I can check it later on (to expire a session) but you can assign it to a normal variable. If you want to record it in your DB, create a field that's assigned to the 'timestamp' setting.
If by 'time out' you want a script that tests when a user last did anything on the site (and log them out if their session has expired) you could use this:
Code: Select all
$last_page_action_timestamp = $_SESSION['timestamp'];
$expiry_time = 2*60; // 2 minutes
echo 'Last timestamp was: ' . $last_page_action_timestamp . '<br />';
echo 'Current timestamp is: ' . mktime() . '<br />';
echo 'Expiry time set to ' . ($expiry_time / 60) . ' minutes<br />';
if (mktime() > ($last_page_action_timestamp + $expiry_time)) {
echo 'Timestamp has expired<br />';
} else {
echo 'Timestamp is still valid<br />';
}HTH,
Mecha Godzilla