Subversion Repositories ALCASAR

Rev

Rev 2112 | Rev 2401 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log

<?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;

//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);
                }
        }
}
else
{
//The file doesn't exist. We create it and write user @IP.
        file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
}
?>