I like to over-complicate things myself. I'd write a cidr class that lets me compare a provided address to a subnet range.
Hmm, offhand I'm not sure if you can link the ip lookup into .htaccess. I know you can do the authentication for basic and whatnots (but you can do that from PHP as well), but for actual IP addresses, I'm not too sure.
well what i do is if a users IP is banned i redirect them to a page saying "your banned" and the details about it.
Regarding the .htaccess the IPs are stored in a database, is it possible to fill the htaccess file from a database or isnt that doable?
What I gave you is viable. You could redirect them with it. You could probably make a script to write an .htaccess file for you with the IPs + necessary tags and have a cronjob or something to update it to include new IPs you add
2/ You said in the form "xxx.xxx.xxx.xxx" and "xxx.xxx.xxx.*"? so you'd have a list of banned individual IP's and banned ranges together in the same banlist?
I would say that having it in "xxx.xxx.xxx.0/bla" form is a bit better as it's a standard way of storing it - I understand if it's a bit of work to change though.
As examples,
"192.168.0.*" is the same as "192.168.0.0/24".
"192.168.*.*" is the same as "192.168.0.0/16".
"192.*.*.*" is the same as "192.168.0.0/8".
If you wanted to ban only the IP "200.15.6.7" you would write "200.15.6.7/32"
I'll work on your script
---------------
is "$deny[]" in the loop the banlist in array form?
Okay, well that wouldnt be much to change yet at all so i can do it that way, how would i put your functions into my script cause mines just a simple in_array
2/ Have your script get the ban list out of the MySQL database and store it in an array (your script does this well as far as I can see ). For sake of argument, let's call the array "$banlist".
3/ Change:
PHP Code:
if (in_array($_SERVER['REMOTE_ADDR'], $banlist)) { **DO STUFF** }
In fact you could store individual IP's in your database even if you forgot to put "/32" at the end. It wouldn't take too long to write a quick script to stick "/32" on the end of an array entry if it didn't find a slash in it.