Hey Guys,

So, I've successfully created my own little CMS ... but, I'm stuck on something. I want to be able to manage other users, but more specifically want to know WHEN they are online and WHEN they aren't online.

This is the session I'm creating to authenticate the user:

<?php

session_start();

if(!isset($_SESSION['MEMBER_NO']) || 
	(trim($_SESSION['MEMBER_NO'])=='')) {
	header("location: login.php");
	exit();
}
?>

MEMBER_NO is the only session variable I've created... but, how can I get this script to send data to MySQL that displays WHEN they're online, and when they aren't online... (if that makes sense)

Or in other words, how can I get this script to send data to MySQL (in real-time) to check whether the session is or isn't present?

Would I need to create a session/cookie that would update or something? I'm stumped...

All help is hugely appreciated!

I don't understand why this is a problem. After line 6 you need something like the following:

mysql_connect ("localhost","id","pw");    
     mysql_select_db ("my_db");  
     $result = mysql_query ("update users set login='$date_time' where user_id=".$_SESSION['MEMBER_NO'].")";

This assumes that you have a user table called "users". You need to decide how you want to handle the status. if you record login and logoff date and time then you could assume that they are online if the logoff date & time is older than the login date & time. You could also set a specific status flag but it could be redundant. This also requires you to force a logoff if a user hasn't be active for a certain period of time. Otherwise, many users could appear to be logged in on a permanent basis.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.