Banning IPs
PHP Coding Tutorials | Submited May 18, 2008
Written by: Mr. Εv¡l
This explains how to ban an IP address with PHP.
It's a decent alternative to using .htaccess..
Notes
Some douche was spamming my guestbook, so I threw this together real quick.
.htaccess is probably more efficient, but this was more convenient at the time, and it works pretty well.
I'll start off by giving you the code since the explanation is minimal.
Code
<?php
$asshat[0] = '24.253.61.96'; // The variable for the banned IPs, you can add more, but increment by one each time
if (in_array($_SERVER['REMOTE_ADDR'],$asshat))
{
header("Location: http://google.com"); // Where the banned person will end up
}
?>
Explanation:
$asshat[0] = '24.253.61.96';
$asshat is the variable, it's also an array.
You can duplicate that line to block more IPs, just increment the number by one.
24.253.61.96 is the IP I banned. You, of course, would have to put in the one you want to ban.
if (in_array($_SERVER['REMOTE_ADDR'], $asshat))
This checks if the person visiting the page has an IP that matches the one(s) in the array.
header("Location: http://google.com");
If it does then they'll be redirected to Google. That's what the header('Location: function does... It redirects >_>
Report whoever is spamming your group to MySpace.