Re: Tracking online users
| From: | The.Wiz | Date: | Thu, 15 May 2003 17:55:55 +0000 |
| Subject: | Re: Tracking online users | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-19956@lists.php.net to get a copy of this message | ||
# Table structure for table
useronline
#
CREATE TABLE useronline (
timestamp int(15) NOT NULL default '0',
ip varchar(40) NOT NULL default '',
FILE varchar(100) NOT NULL default '',
PRIMARY KEY (timestamp),
KEY ip (ip),
KEY FILE (FILE)
) TYPE=MyISAM;
# --------------------------------------------------------
<?PHP
// Variables should already be in config.php
//get the time
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;
//connect to database
mysql_connect($host, $dbusername, $dbpassword);
//insert the values
$insert = mysql_db_query($dbname, "INSERT INTO useronline VALUES
('$timestamp','$ip','$PHP_SELF')");
if(!($insert)) {
print "Useronline Insert Failed > ";
}
//delete values when they leave
$delete = mysql_db_query($dbname, "DELETE FROM useronline WHERE
timestamp<$timeout");
if(!($delete)) {
print "Useronline Delete Failed > ";
}
//grab the results
$result = mysql_db_query($dbname, "SELECT DISTINCT ip FROM useronline WHERE
file='$PHP_SELF'");
if(!($result)) {
print "Useronline Select Error > ";
}
//number of rows = the number of people online
$user = mysql_num_rows($result);
//spit out the results
mysql_close();
if($user == 1) {
print("<center><b><font class=footer>There is $user user
online\n</font></b></center>");
} else {
print("<center><b><font class=footer>There are $user users
online\n</font></b></center>");
}
?>
"Guru P Chaturvedi" <bangboy2k2@hotmail.com> wrote in message
news:20030509185935.91630.qmail@pb1.pair.com...
> Hi,
> i want to show the total number of users logged in [http session] to the
> site at any point of time. How can this be done. What are the methods i
need
> to make use of to accomplish this. kindly help me out in this regard.
>
> with Warm Regards,
> Guru.
> ---------------------------------------
> Phone: (+91)9845290270
> URL: www.gangarasa.com
> Yahoo IM: guru4vedi
> MSN: guru4vedi@gangarasa.com
> ---------------------------------------
>
>