Subversion Repositories ALCASAR

Rev

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

Rev Author Line No. Line
2009 raphael.pi 1
<?php
2
 
2394 tom.houday 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';
5
$user_ip = $_SERVER['REMOTE_ADDR'];
2009 raphael.pi 6
 
2394 tom.houday 7
if ((!file_exists($filename)) || (filesize($filename) === 0)) {
8
	// Creating file and write user @IP.
9
	file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL);
10
} else {
11
	// If we found duplicate user IP, it will not be writen again
12
	$found = false;
13
	$fh = fopen($filename, 'r');
14
	while (!feof($fh)) {
15
		$line = fgets($fh, 1024);
16
		if (preg_match('/^'.preg_quote($user_ip).':/', $line)) {
17
			$found = true;
18
			break;
19
		}
20
	}
21
	fclose($fh);
22
 
23
	// else we write user IP in the file
24
	if (!$found) {
25
		file_put_contents($filename, $user_ip.':TEMP'.PHP_EOL, FILE_APPEND);
26
	}
2009 raphael.pi 27
}