thanks guys i found it out here it is
Code:
$ip = trim($_SERVER['REMOTE_ADDR']);
$myFile = "testFile.txt";
$fh = fopen($myFile, 'a+')or die ("fail to read the file");
$theData = fread($fh, filesize($myFile));
$theData = trim($theData);
//echo $theData;
$savefile = explode(" ",$theData);
foreach ($savefile as $value) {
//print $value." - ". $ip."<br />";
if($value == $ip){
$flag = 1;
break;
}
//echo $value."<br />";
}
if(isset($flag)){
echo "Ip found";//now u can do what ever u want
}else{
$count = count($savefile);
if($count >4000){ // total number of record
$savefile[] = $ip;
$savefile = array_slice($savefile,1,$count);
//print_r($savefile);
$str = implode(" ",$savefile);
$str = trim($str);
$temp = "temp.txt";
$new = fopen($temp, 'w') or die("can't open file");
fwrite($new, $str);
unlink("file/testFile.txt");
rename("file/temp.txt","file/testFile.txt");
}else{
$ip = " ".$ip;
fwrite($fh, $ip);
}
echo "Ip not found";
}
fclose($fh);