Mi sembra strano che tu non riesca ad intecettare l'ip del tuo visitatore indesiderato.
Ho rivisto un po' il tuo codice che aveva alcune cose anomale (perchè leggere una riga del file di log e poi non far nulla dei dati letti?).
HO inserito un reindirizzamento lato server (con header location) invece che con js: il tuo visitatore potrebbe usare un browser con js disattivato e quindi ignorare il reindirizzamento.
Codice PHP:
<?PHP
$fd = fopen ("ban.txt", "r");
while (($buffer=fgets($handle, 4096)) !== false) {
$buffer=chop($buffer);
if ($buffer==$SERVER['REMOTE_ADDR']) {
//if so write it to a logfile
$string = "$ip::PERMISSION DENIED\n";
$log = fopen("log.txt", "a+");
$string = fwrite($log, $string);
fclose($log);
// throw them to another page
header('location:pagina_bannati.php');
die();
}
}
fclose ($fd);
?>