I have no idea how a simple things like this can be so difficult :o
The thing is, we need to know what format are you storing your data in.
Is every IP address stored on a separate line?
If it is, you can use:
//add the current IP address to the file
function addIp($file) {
$fp = fopen($file, "a");
OR return false;
fwrite($fp, "\n" . $_SERVER['REMOTE_ADDR']);
fclose($fp);
return true;
}
//check if the current IP is already listed
function checkIp($file) {
$ip_array = file($file);
foreach ($ip_array as $ip) {
if (trim($ip) == $_SERVER['REMOTE_ADDR']) {
return true;
}
}
return false;
}
Let's see what you need:
1. Check if user's IP is listed -> use checkIp()
2. If it is listed, dont increment counter
3. Else, use addIp(), then increment counter