Subversion Repositories ALCASAR

Rev

Rev 2108 | Go to most recent revision | Details | Last modification | View Log

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