Tuesday, August 3, 2010

Wap Useronline

ode:
CREATE TABLE useronline (
  timestamp int(15) DEFAULT '0' NOT NULL,
  ip varchar(40) NOT NULL,
  file varchar(100) NOT NULL,
  PRIMARY KEY (timestamp),
  KEY ip (ip),
  KEY file (file)
);
Script code:

PHP Code:
$server                 "localhost"$db_user                "root"$db_pass                ""$database               "online";
$timeoutseconds         1000$timestamp=time(); $timeout=$timestamp-$timeoutsecondsmysql_connect($server$db_user$db_pass) or die ("Useronline Database CONNECT Error"); mysql_db_query($database"INSERT INTO useronline VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')") or die("Useronline Database INSERT Error"); mysql_db_query($database"DELETE FROM useronline WHERE timestamp<$timeout") or die("Useronline Database DELETE Error"); $result=mysql_db_query($database"SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'") or die("Useronline Database SELECT Error"); $user  =mysql_num_rows($result); mysql_close();
if (
$user==1) {
       echo
"online: $user user";
       }
       else
       {
       echo
"online: $user users";}

?>
include it to your page eg.

PHP Code:
include("useronline.php"); ?>

No comments:

Post a Comment