I was wondering how to go about inserting a time out function on my website using sessions in PHP. Basically, I am looking for a timeout code that logs a user out and sends them back to the login (index.php) page after the user is idle for 5 mins.
Would I first need to create a 'timeout' field in my SQL database? If so, what information would I need to do that; or what values, etc. do I need to set that field equal to?
Here is my index.php, which is a login page for my website. If someone can take a look over the code, and provide me with any instructions or directions I need to take in order to get a timeout session working, I would appreciate it!!!
index.php
==========================
=======
<?php
require_once('db.php');
include('functions.php');
if(isset($_POST['Login']))
{
if($_POST['username']!='' && $_POST['password']!='')
{
//Use the input username and password and check against 'users' table
$query = mysql_query('SELECT ID, Username, Active, Level_access FROM users WHERE Username = "'.mysql_real_escape_strin
g($_POST['
username']
).'" AND Password = "'.mysql_real_escape_strin
g(md5($_PO
ST['passwo
rd'])).'"'
);
if(mysql_num_rows($query) == 1)
{
$row = mysql_fetch_assoc($query);
if($row['Active'] == 1)
{
session_start();
$_SESSION['user_id'] = $row['ID'];
$_SESSION['logged_in'] = TRUE;
switch($row['Level_access'
])
{
case 1:
{
header("Location: control_panel.php");
break;
}
case 2:
{
header("Location: members.php");
break;
}
}
}
else {
$error = 'Your user account was not activated. Please open the email that was sent and click on the activation link.';
}
}
else {
header("Location: login_fail.php");
}
}
else {
$error = 'Please enter both your username and password to access your account';
}
}
?>
<?php if(isset($error)){ echo $error;}?>
Start Free Trial