Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 2393 → Rev 2394

/web/still_connected.php
1,39 → 1,27
<?php
 
//store user @IP who can join this page (still have their status.php tab open) in a file.
$filename='/var/tmp/havp/current_users.txt';
$change_me = 1;
// store user @IP who can join this page (still have their status.php tab open) in a file.
$filename = '/var/tmp/havp/current_users.txt';
$user_ip = $_SERVER['REMOTE_ADDR'];
 
//check if file exists
if(file_exists($filename)){
$current_users_file = fopen($filename, "r");
$content = file($filename);
fclose($current_users_file);
// if file is empty, we put user @IP in it.
if(empty($content))
{
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
}
else
{
// if we found duplicate user IP, it will not be writen again
foreach($content as $line){
$line = preg_replace('/\s+/', '', $line); #remove whitespace
if($line == $_SERVER['REMOTE_ADDR'])
{
$change_me = 0;
}
}
// else we write user IP in the file
if($change_me)
{
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL , FILE_APPEND);
}
}
if ((!file_exists($filename)) || (filesize($filename) === 0)) {
// Creating file and write user @IP.
file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL);
} else {
// If we found duplicate user IP, it will not be writen again
$found = false;
$fh = fopen($filename, 'r');
while (!feof($fh)) {
$line = fgets($fh, 1024);
if (preg_match('/^'.preg_quote($user_ip).':/', $line)) {
$found = true;
break;
}
}
fclose($fh);
 
// else we write user IP in the file
if (!$found) {
file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL, FILE_APPEND);
}
}
else
{
//The file doesn't exist. We create it and write user @IP.
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
}
?>