I have moved further with this and just about have it working. Currently running into a wall however.
When a user logs in they automatically get logged out as soon as the new page loads after hitting log in.
The reason for this is because of the check that runs on each page to see if the user has been active within a 15 minute period.
Databae:
id int(11) NOT NULL auto_increment,
Username text NOT NULL,
lastonline bigint(20) NOT NULL default '0',
PRIMARY KEY (id)
The login:
if($row['Activated'] > 0)
{
$_SESSION['s_logged_n'] = 'true';
$_SESSION['s_username'] = $username;
$_SESSION['s_name'] = $row['Name'];
$time = time();
$insertuser="INSERT INTO online(Username,lastonline) values('$username','$time')";
mysql_query($insertuser) or die("Could not login insert user");
header("Location: index.php");
}
else
{
header("Location: l_error.php");
I'm pretty sure that is working correctly and adding the time they logged in.
This is the script that runs each page:
session_start();
$lastonline = time();
if ($_SESSION['lastonline'] <= (time() - 900)) // 900 = 15 minutes (60x15)
{
$username = $_SESSION['s_username'];
$query = "DELETE FROM online WHERE username = '".mysql_real_escape_string($_SESSION['s_username'])."';";
$result = mysql_query($query);
$_SESSION['s_logged_n'] = '';
$_SESSION['s_name'] = '';
$_SESSION['s_username'] = '';
session_destroy();
}
else
{
$username = $_SESSION['s_username'];
$_SESSION['lastonline'] = time();
$query = "INSERT INTO online(Username, lastonline) VALUES('${lastonline}')";
$updateonline="Update online set username='$username',lastonline='$lastonline'";
mysql_query($updateonline) or die("Could not update online");
}
It seems the script is skipping the original IF statement to check the time and just destroys the session as soon as the user logs in.
Is their anything missing in either of those scripts that may be causing the problem?