ok so I've been playing around with adding a counter to track the membership and who is logged in right now. I just want to display the number of members that are online right now on my login page for people to see. So far i've tried this several ways but settled on the following method and it works until more than 1 person attempt to logout then i get an error and i'm not sure what is causing it.
First thing first the process:
when a user hits my main index page I query the user_online table and just get a record count. I track my users by user_id and timestamp in this table. query is fine no problem there.
next when they login I initiate a session and insert the user_ID from my users table into the session. next I take that information from the session and check to make sure I don't already have that user listed in my user_online table all good there. when I am testing this the problem happens on my logout script where I end the session and destroy it. I'm wondering if this is a problem only because i am logging in testing it with multiple users on my specific computer which also happens to be my server.
take a look:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL & ~E_NOTICE);
session_start();
//fill in some basic info
$server = "localhost";
$db_user = "user";
$db_pass = "password";
$database = "database";
//get the time
$timestamp = time();
$timeout = $timestamp+$timeoutseconds;
$id = $_SESSION['user_id'];
//connect to database
mysql_connect($server, $db_user, $db_pass);
//insert the values
mysql_db_query($database, "DELETE FROM user_online WHERE user_id =".$id) or die(mysql_error());
mysql_close();
unset ($_SESSION);
session_destroy();
header('location: index.php');
?>
I can logout with the first user, then i go to my second instance of the website and logout with a second user and it errors out on me. any feedback on this would be appreciated.