Subversion Repositories ALCASAR

Rev

Rev 2108 | Rev 2278 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
2009 raphael.pi 1
<?php
2
 
2112 richard 3
//store user @IP who can join this page (still have their status.php tab open) in a file.
2108 richard 4
$filename='/var/tmp/havp/current_users.txt';
2009 raphael.pi 5
$change_me = 1;
6
 
2112 richard 7
//check if file exists
2009 raphael.pi 8
if(file_exists($filename)){
2112 richard 9
        $current_users_file = fopen($filename, "r");
10
	$content = file($filename);
11
	fclose($current_users_file);
12
// if file is empty, we put user @IP in it.
2009 raphael.pi 13
        if(empty($content))
14
        {
2112 richard 15
                file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
2009 raphael.pi 16
        }
17
        else
18
        {
2112 richard 19
// if we found duplicate user IP, it will not be writen again
2009 raphael.pi 20
                foreach($content as $line){
21
                        $line = preg_replace('/\s+/', '', $line);
22
                        if($line == $_SERVER['REMOTE_ADDR'])
23
                        {
24
                                $change_me = 0;
25
                        }
26
                }
2112 richard 27
// else we write user IP in the file
2009 raphael.pi 28
                if($change_me)
29
                {
30
                        file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL , FILE_APPEND);
31
                }
32
        }
33
}
34
else
35
{
2112 richard 36
//The file doesn't exist. We create it and write user @IP.
2009 raphael.pi 37
	file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
38
}
39
?>