Hello Folks,
For some while now I've been very successfully using the kloth.net
bad robots trap. It uses a flatfile reference called blacklist.dat.
Every couple of months I manually trim this file, usually when it has
grown to around 200 lines or more. I take out the first 50 entries,
then save the file. Is there a way of automating this procedure?
The blacklist.dat file is written to by activation of the trap, so what
I'd like to be able to do is...
test whether there are 200 entries
if so, read in the file starting at line 50
then save the trimmed file.
I'm reasonably OK with PHP to generate HTML content, but a complete
duffer when it comes to file handling. Any help you give will be be very
gratefully received. Thanks in advance.
Automating a flatfile maintenance routine
Moderator: General Moderators
Re: Automating a flatfile maintenance routine
Hello Folks,
Progress so far...
This is the PHP code that I've added. Will this work reliably?
Progress so far...
Code: Select all
$filearray = file($filename);
$c = count($filearray);
if ($c > $limit) {
$fp = fopen($filename,"w") or die ("Error opening file ...");
for($i=($c < 150 ? 0 : $c-150);$i < $c;++$i) {
fputs($fp,$filearray[$i]);
}
fwrite($fp,"$REMOTE_ADDR $datum \n");
fclose($fp);
} else {
$fp = fopen($filename,"a+") or die ("Error opening file ...");
fwrite($fp,"$REMOTE_ADDR \n");
fclose($fp);
}
Last edited by onion2k on Thu May 21, 2009 9:17 am, edited 1 time in total.
Reason: Set your signature if you want a signature. Don't add pointless links to posts.
Reason: Set your signature if you want a signature. Don't add pointless links to posts.