Ok, here's the project.
Portal for my daughter's 2nd grade class. Working on a "Who's Online", using cookies, with user id ($uid) and user name ($user_name).
Question is: how do I collect the uid's & user names from the cookies & put them in an array to loop thru so it will show everyone that is online?
Thx in advance.
Mike
Who's online
Moderator: General Moderators
cookies...
Hey,
I wrote a script that does exact same thing, But doesnt use cookies it use sql...
But if you dont have MySQL access, Then I cant help. Not with cookies anyway 
I wrote a script that does exact same thing, But doesnt use cookies it use sql...
Code: Select all
<?PHP
/*
Author: pHaZed
URL: www.net-espionage.com
Script: Useronline
*/
$host= "127.0.0.1"; // MySQL Server,
$db_user= "user"; // MySQL Username
$db_pass= "pass"; // MySQL Password
$database= "data"; // Database Name
$timeoutseconds = 300; // Timeout value in seconds
$timestamp=time();
$timeout=$timestamp-$timeoutseconds;
mysql_connect($host, $db_user, $db_pass) or die (mysql_error());
mysql_db_query($database, "INSERT INTO useronline VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')") or die(mysql_error());
mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout") or die(mysql_error());
$result=mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'") or die(mysql_error());
$user =mysql_num_rows($result);
mysql_close();
if ($user==1)
{
echo"<font face=verdana size=1 color=#FFFFFF><B>There is $user User online</b></font>"; //single
}
else
{
echo"<font face=verdana size=1 color=#FFFFFF><B>There are $user Users online</b></font>"; //plural
}
?>DSM: Yeah, take a look on PHPClasses.org for User Online classes, or use the above script. They are out there in bulk...maybe a google search will turn up something.
you'd be better off checking for the cookie and adding that name to a text file or a database with a timestamp, then defining a "timeout" for how long ago you want to show.
Since HTTP is stateless, you can't tell when people leave the site - so you just have to make a guess at an average time.
-enygma
Since HTTP is stateless, you can't tell when people leave the site - so you just have to make a guess at an average time.
-enygma
- EvilWalrus
- Site Admin
- Posts: 209
- Joined: Thu Apr 18, 2002 3:21 pm
- Location: Springmont, PA USA