1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| $instant_present = time();
$ip_client = $_SERVER['REMOTE_ADDR'];
$ip_connues = array();
$record = fopen("historique.txt", "r");
while (($buffer = fgets($record, 4096)) !== false) {
$ip_enregistree = strtok($buffer, "|");
$heure_enregistree = strtok("\n");
array_push($ip_connues, array($ip_enregistree => $heure_enregistree));
}
fclose($record);
if (!is_array($ip_connues)){
echo " \$ip_connues n'est pas un tableau <br> \n";
}
else{
foreach($ip_connues AS $ip_enregistree => $heure_enregistree){
if($ip_enregistree == $ip_client && $instant_present > ($heure_enregistree+300)){
$record = fopen("historique.txt", "w+");
fwrite($record, $ip_client."|".$instant_present."\n");
fclose($record);
}
else{
if(!preg_match("/$ip_client/", "$ip_connues")){
$record = fopen("historique.txt", "w+");
fwrite($record, $ip_client."|".$instant_present."\n");
fclose($record);
}
}
}
}
if(!preg_match("/$ip_client/", "$ip_connues")){
$record = fopen("historique.txt", "w+");
fwrite($record, $ip_client."|".$instant_present."\n");
fclose($record);
} |