Forum Moderators: coopster
$filename = "/path/to/file/";
$newcontent = "My new content here \r\n";
$handle = fopen($filename, 'r');
$newcontent .= fread($handle,filesize($filename)); // add old content to new
fclose($handle);
$handle = fopen($filename, 'w+');
fwrite($handle, $newcontent.$oldcontent,strlen($newcontent));
fclose($handle);
It's funny, because I work too on a badbot trap (with your code it is now finished).
If you want we can exchange our views on this subject.
<?
$datum = date("d-m-Y (D) H:i:s",$tmestamp);
//
$filename = "./.htaccess";
# IP in regex
$remaddr = $REMOTE_ADDR;
$remaddr = preg_quote ($remaddr, "/");
// New line
$newcontent = "SetEnvIf Remote_Addr ^".$remaddr."$ ban # $datum\r\n";
$handle = fopen($filename, 'r');
$newcontent .= fread($handle,filesize($filename));
fclose($handle);
// Open and write new content in .htaccess (CHMOD 644)
$handle = fopen($filename, 'w+');
fwrite($handle, $newcontent.$oldcontent,strlen($newcontent));
fclose($handle);
?>