Zubrag.com
August 17, 2019, 09:36:02 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: User Online  (Read 5453 times)
SlovenianBoy
Newbie
*
Posts: 5


« on: January 18, 2008, 05:05:38 PM »

Code:
<?php 
//vars 
$file_name "online.txt"
$c_time time(); 
$timeout 300
$time $c_time $timeout
$ip getenv("REMOTE_ADDR"); 

if(!
file_exists($file_name)){ 
$fp fopen($file_name"w"); 
fwrite($fp"<?php die('Restricted File');?>
\n");
fclose($fp);
}

//write to file
$fp = fopen($file_name, "a");
$write = $ip."||".$c_time."\n";
fwrite($fp, $write);
fclose($fp);

//open file to as array, to count online
$file_array = file($file_name);
$online_array = array();
for($x = 1; $x < count($file_array); $x++){
list($ip, $ip_time) = explode("||", $file_array[$x]);
if($ip_time >= $time){
array_push($online_array, $ip);
}
}//end for

$online = array_unique($online_array);
$online = count($online);
if($online == "1"){
print "User online: $online"."<br>";
}else{
print "Users online: $online"."<br>";
}
?> 

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC