Hi All,
I have a script that runs on every page to check whether the user is logged in and if not re-direct to the login page. I wanted this script to also update the users database column ‘LastTimeSeen’ so that I can run a query to see who is online or at least within 5 minutes.
My current code is;-
[php]include(‘login_config.php’);
session_start();
$user_check=$_SESSION[‘login_user’];
$ses_sql=mysqli_query($db,"select username, level, id from users where username=’$user_check’ ");
$row=mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_session =$row[‘username’];
$login_level =$row[‘level’];
$login_id =$row[‘id’];
if(!isset($login_session))
{
header(“Location: …/login/”);
}[/php]
I know I need something along the lines of this;-
UPDATE users SET LastTimeSeen = NOW() WHERE id = $the_user_id
However I’m struggling to implement???
Once its working I will run the following query;-
SELECT COUNT(*) FROM users WHERE LastTimeSeen > DATE_SUB(NOW(), INTERVAL 5 MINUTE)
Any help is appreciated!!!