Online Users with PHP - Php

Online Users

Snippet Code


  
Rate this page :
  [ 0 votes]

This script is used to find the number of online users.

<?php $server = "abc"; $dbuser = "abc"; $dbpass = "abc"; $database = "abc"; $db = mysql_connect($server, $dbuser,$dbpass); mysql_select_db($database,$db); $timeoutseconds = 300; //5 minutes $timest&= time(); $timeout = $timestamp-$timeoutseconds; $insert = mysql_query("INSERT INTO useronline VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')",$db); if(!($insert)) { print "Useronline Insert Failed > "; } $delete = mysql_query("DELETE FROM useronline WHERE timestamp<$timeout",$db); if(!($delete)) { print "Useronline Delete Failed > "; } $result = mysql_query("SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'",$db); if(!($result)) { print "Useronline Select Error > "; } $user = mysql_num_rows($result); mysql_close(); if($user == 1) { print("$user user onlinen"); } else { print("$user users onlinen"); } ?> //The table structure CREATE TABLE useronline ( timest&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) );

Tags


Ask Questions

Ask Question