Warning: fopen(online.txt) [function.fopen]: failed to open stream: Permission denied in /home/a5566715/public_html/modules/online_now.php on line 15
Warning: fwrite(): supplied argument is not a valid stream resource in /home/a5566715/public_html/modules/online_now.php on line 19
Warning: fclose(): supplied argument is not a valid stream resource in /home/a5566715/public_html/modules/online_now.php on line 21
Warning: file(online.txt) [function.file]: failed to open stream: No such file or directory in /home/a5566715/public_html/modules/online_now.php on line 25
Warning: Invalid argument supplied for foreach() in /home/a5566715/public_html/modules/online_now.php on line 29
Aquí teneis el archivo online_now.php
Código PHP:
<?
function online_now(){
$remote = $_SERVER["REMOTE_ADDR"];
$file = "online.txt";
$timeoutseconds = 60;
$timestamp = time();
$timeout = ($timestamp-$timeoutseconds);
$fp = fopen("$file", "a+");
$write = $remote."||".$timestamp."\n";
fwrite($fp, $write);
fclose($fp);
$online_array = array();
$file_array = file($file);
foreach($file_array as $newdata){
list($ip, $time) = explode("||", $newdata);
if($time >= $timeout){
array_push($online_array, $ip);
}
}
$online_array = array_unique($online_array);
$online = count($online_array);
if($online == "1"){
echo "<p><b>Total users online:</b> $online</p>";
}else{
echo "<p><b>Total users online:</b> $online</p>";
}
}
online_now();
?>