Subversion Repositories ALCASAR

Rev

Rev 2108 | Rev 2278 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2108 Rev 2112
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
//store in a file user @IP who can join this page.
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 avoid duplicate user @IP
-
 
6
$change_me = 1;
5
$change_me = 1;
7
 
6
 
8
//check if filename exists
7
//check if file exists
9
if(file_exists($filename)){
8
if(file_exists($filename)){
10
        $fichier = fopen($filename, "r");
9
        $current_users_file = fopen($filename, "r");
11
        $content = file($filename);
10
	$content = file($filename);
12
 
-
 
-
 
11
	fclose($current_users_file);
13
	//if file is empty, we put user @IP in it.
12
// if file is empty, we put user @IP in it.
14
        if(empty($content))
13
        if(empty($content))
15
        {
14
        {
16
                file_put_contents($filename, $_SERVER['REMOTE_ADDR']);
15
                file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
17
        }
16
        }
18
        else
17
        else
19
        {
18
        {
20
        	//if we found duplicate IP, it will not write user @IP in filename (set change_me = 0)
19
// if we found duplicate user IP, it will not be writen again
21
                foreach($content as $line){
20
                foreach($content as $line){
22
                        $line = preg_replace('/\s+/', '', $line);
21
                        $line = preg_replace('/\s+/', '', $line);
23
                        if($line == $_SERVER['REMOTE_ADDR'])
22
                        if($line == $_SERVER['REMOTE_ADDR'])
24
                        {
23
                        {
25
                                $change_me = 0;
24
                                $change_me = 0;
26
                        }
25
                        }
27
 
-
 
28
                }
26
                }
29
 
-
 
30
		//if user @IP does not exist, we will write it in filename
27
// else we write user IP in the file
31
                if($change_me)
28
                if($change_me)
32
                {
29
                {
33
                        file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL , FILE_APPEND);
30
                        file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL , FILE_APPEND);
34
                }
31
                }
35
        }
32
        }
36
 
-
 
37
}
33
}
38
else
34
else
39
{
35
{
40
	//we create filename and we put user @IP in it.
36
//The file doesn't exist. We create it and write user @IP.
41
	file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
37
	file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
42
}
38
}
43
 
-
 
44
?>
39
?>