<?
//تحديث الوثت بعد
$timeoutseconds  =  300 ;


//get the time
$timestamp  =  time ();
$timeout  =  $timestamp - $timeoutseconds ;
$ip=  $_SERVER[REMOTE_ADDR];
$loc = $_SERVER[PHP_SELF] ;
if(!isset($_COOKIE[traidusername])  ){
 $username="";
}else{
$username= $_COOKIE['traidusername'];
}

$search = @mysql_db_query("$dbName", "SELECT * FROM `online` WHERE `online_ip` = '$ip' ") ;
$get = @mysql_affected_rows();
@mysql_free_result($search);
if(($get)==('0')){
$add = mysql_db_query("$dbName", "
INSERT INTO `online` ( `online_id` , `online_ip` , `online_location` , `user_name` , `online_time` )
VALUES (NULL , '$ip', '$loc', '$username', '$timestamp');
") ;
@mysql_free_result($add);
}else{
$update = @mysql_db_query("$dbName", "UPDATE `online` SET `online_location` = '$loc' WHERE `online`.`online_ip` = '$ip' LIMIT 1 ;") ;
@mysql_free_result($update);
}
$delete = @mysql_db_query("$dbName", "DELETE FROM `online` WHERE `online_time` < '$timeout' ") ;
@mysql_free_result($delete);
$getall = @mysql_db_query("$dbName", "SELECT * FROM `online`") ;
$totalonline = mysql_affected_rows();


$getvistor = @mysql_db_query("$dbName", "SELECT * FROM `online` WHERE `user_name` = '' ") ;
$gettotalvistor = mysql_affected_rows();
if(($gettotalvistor)==('0')){
$totalvistor ="لا يوجد زوار حاليا";
}else{
$totalvistor = $gettotalvistor;
}

$getusers = @mysql_db_query("$dbName", "SELECT * FROM `online` WHERE `user_name` != '' ") ;
$gettotalusers = mysql_affected_rows();
if(($gettotalusers) ==('0')){
$tusers = "لايوجد اعضاء حاليا";
}else{
while  ($gu = mysql_fetch_array($getusers)){
$username = $gu[user_name];
$loc =  $gu[online_location];
$tusers = $username."&nbsp;&nbsp;,";
}

}





?>