This is a very old tiny script that I've used to ban ip addresses from the php page/website.
Bans are not a good solution in terms of performances of the website, expecially if the bans list is long or complex to elaborate.
You can just call the checkbans() functions from your php file.
The storage file should be outside the web root or, if you are using it with the php extension, add
This is not a solution to suggest but I've found it in my old crappy code (more than five years ago).
I actually use a mixed solution that involves .htaccess files.
function checkbans(){
$handle = fopen("ipbans.dat.php", "r");
if($handle === false){ return false; }
while (!feof($handle)) {
$line = trim(fgets($handle, 32));
if( $line == $_SERVER['REMOTE_ADDR'] )
{
fclose($handle);
//header('Location: http://www.google.com'); //redirect to google?
exit();
}
}
fclose($handle);
}
You can just call the checkbans() functions from your php file.
The storage file should be outside the web root or, if you are using it with the php extension, add
<?php exit(); ?>in the first line.
This is not a solution to suggest but I've found it in my old crappy code (more than five years ago).
I actually use a mixed solution that involves .htaccess files.
Comments
Post a Comment