i-CONICA
asked on
PHP MySQL simple active guests display
Hi,
I've got this which I hoped would show how many active guests are visiting the site in the past hour, it's not working though and I'm not sure why.
Also, I don't know how I would remove users after the hour they should be stored for... I don't want the table filling up forever...
Can anyone offer advice on this? I think several parts maybe flawed.
Thanks.
I've got this which I hoped would show how many active guests are visiting the site in the past hour, it's not working though and I'm not sure why.
Also, I don't know how I would remove users after the hour they should be stored for... I don't want the table filling up forever...
Can anyone offer advice on this? I think several parts maybe flawed.
Thanks.
$d = time() - 60 * 60; //last 1 hour
$q = mysql_query("SELECT username FROM `guests` WHERE time > '$d'");
if (mysql_affected_rows($q) > 0) {
echo "<ul>";
while ($users = mysql_fetch_array($q)) {
echo "<li>{$users[0]}</li>";
}
echo "</ul>";
}
if (isset($_SESSION['username'])) {
$user = $_SESSION['username'];
$date = time();
mysql_query("REPLACE INTO `guests` (username,time) VALUES('$user','$date')");
}
else{
$_SESSION['username'] = $_SERVER["REMOTE_ADDR"];
$user = $_SESSION['username'];
$date = time();
mysql_query("INSERT INTO `guests` (username,time) VALUES('$user','$date')");
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER