tags:

views:

37

answers:

2

Hello all. I am having problems with idiots coming on my site and just being abusive. I can ban their account and then put deny from xxx.xxx.xxx.xxx in the htaccess file.

Is there anything else i can do to stop them getting back?

The main reason for this question is, whats the best way to write the deny from to the htaccess as an option in my admin panel?

Thanks

+5  A: 

Alternatively, just load the list of IPs into a database, and check to see if $_SERVER['REMOTE_ADDR'] exists in your ban list, then have php just echo a "Go away" message.

As Steven pointed out, you would also have better performance by converting the IPs to numbers using ip2long() and then searching the database using numbers, as this would be much more efficient than search by string.

webdestroya
This is a solution that should suit your case perfectly fine. If you're planning to amass a large number of bans (such as with automatic banning on a highly-trafficked site), you might see value in using `ip2long()` and `long2ip()` instead of what would amount to full text search on the database.
Steven Xu
A: 

You can perform an IP check when they access any part of your website. In your admin panel you store a list of banned IP addresses in a database right ? So heres a solution with that in mind.

checkBannedIP();


function checkBannedIP() {
    $ipAddresses = getBannnedIPs(); // Array('44.55.66.898', '465.22.78.365');
    if(in_array($_SERVER['REMOTE_ADDR'], $ipAdresses)) {
        header("Location: www.google.com");
    }
}

All you need to do is created getBannedIPs() function which is a list of the IP's in your database.

So just have that function in a shared .php file and call checkBannedIP() at the top of every page on your site. This means it will redirect banned users IP to google.com. People messing about on sites are more likely to stop if they're frustrated with redirection.

Paul Dragoonis
This would essentially select ALL the banned IPs EACH time someone hit the site... which would amount to a HUGE cpu load.
webdestroya
That would depend on the amount of IP's he wants to store. If it's a considerable amount then caching techniques or reading files come into play.
Paul Dragoonis
Sorry Paul, there's 1 more problem with your solution. It only sends a redirection header to the browser, it doesn't kill the script. So if the browser ignores the redirection, they can still do whatever they want. So you should put a "die()" statement after the header() statement.
Fair enough if you want to exit after it then use exit; or die(); Either work :)
Paul Dragoonis