0,0 → 1,44 |
<?php |
|
//store in a file user @IP who can join this page. |
$filename='/tmp/current_users.txt'; |
//change me avoid duplicate user @IP |
$change_me = 1; |
|
//check if filename exists |
if(file_exists($filename)){ |
$fichier = fopen($filename, "r"); |
$content = file($filename); |
|
//if file is empty, we put user @IP in it. |
if(empty($content)) |
{ |
file_put_contents($filename, $_SERVER['REMOTE_ADDR']); |
} |
else |
{ |
//if we found duplicate IP, it will not write user @IP in filename (set change_me = 0) |
foreach($content as $line){ |
$line = preg_replace('/\s+/', '', $line); |
if($line == $_SERVER['REMOTE_ADDR']) |
{ |
$change_me = 0; |
} |
|
} |
|
//if user @IP does not exist, we will write it in filename |
if($change_me) |
{ |
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL , FILE_APPEND); |
} |
} |
|
} |
else |
{ |
//we create filename and we put user @IP in it. |
file_put_contents($filename, $_SERVER['REMOTE_ADDR'].PHP_EOL); |
} |
|
?> |