Subversion Repositories ALCASAR

Rev

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

Rev 2278 Rev 2394
Line 1... Line 1...
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
$user_ip = $_SERVER['REMOTE_ADDR'];
6
 
6
 
7
//check if file exists
-
 
8
if(file_exists($filename)){
-
 
9
        $current_users_file = fopen($filename, "r");
7
if ((!file_exists($filename)) || (filesize($filename) === 0)) {
10
	$content = file($filename);
-
 
11
	fclose($current_users_file);
-
 
12
// if file is empty, we put user @IP in it.
8
	// Creating file and write user @IP.
13
        if(empty($content))
-
 
14
        {
-
 
15
                file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
9
	file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL);
16
        }
-
 
17
        else
-
 
18
        {
10
} else {
19
// if we found duplicate user IP, it will not be writen again
11
	// If we found duplicate user IP, it will not be writen again
20
                foreach($content as $line){
-
 
21
                        $line = preg_replace('/\s+/', '', $line); #remove whitespace
-
 
22
                        if($line == $_SERVER['REMOTE_ADDR'])
-
 
23
                        {
12
	$found = false;
24
                                $change_me = 0;
-
 
25
                        }
13
	$fh = fopen($filename, 'r');
26
                }
14
	while (!feof($fh)) {
27
// else we write user IP in the file
15
		$line = fgets($fh, 1024);
28
                if($change_me)
16
		if (preg_match('/^'.preg_quote($user_ip).':/', $line)) {
29
                {
17
			$found = true;
30
                        file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL , FILE_APPEND);
-
 
31
                }
18
			break;
32
        }
19
		}
33
}
20
	}
34
else
21
	fclose($fh);
35
{
22
 
36
//The file doesn't exist. We create it and write user @IP.
23
	// else we write user IP in the file
-
 
24
	if (!$found) {
37
	file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL);
25
		file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL, FILE_APPEND);
-
 
26
	}
38
}
27
}
39
?>
-