Subversion Repositories ALCASAR

Rev

Rev 2112 | Rev 2394 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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