Forum Moderators: phranque

Message Too Old, No Replies

.htaccess Dynamically Block IP After it

         

xcrashorx

4:56 am on Sep 12, 2006 (gmt 0)

10+ Year Member



I have searched and can only find the php way. So yet I wonder if there is a way to block an ip if that ip loads [website.com...] more then lets say x times? With .htaccess I’m hoping.. Or even an easy way to add like a counter to my error.php file, and yes the actual file I want to be used is in php code? Thanks for any ideas...

xcrashorx

3:28 am on Sep 14, 2006 (gmt 0)

10+ Year Member



Am i in the wrong spot? Or can this not be done? Hello........Hello........Hello, Echo Echo Echo

Romeo

10:44 am on Sep 14, 2006 (gmt 0)

10+ Year Member



Welcome to WebmasterWorld, xcrashorx.

There is no easy way with .htaccess. You have to store dynamic counters for every IP address somewhere and compare them with X.

If you want a complex logic, you would have to implement it.
In this case you would need something like this:
After creating a database table holding an indexed row for IP-addresses and one for a counter,
just put the following small logic at the top of your file.php:
Look for the counter of a certain IP-address in the database.
If it is there and < X, then update that record and write back an X+1.
If it is not there, then insert a new record for that IP address with X=1.
If the counter is <= X then proceed with giving out the page, else just say 'no' and exit.
Perhaps you may wish to add a 3rd row holding an updated datetime stamp, too, so that you could delete old records after a while, which would require some additional logic then.

Kind regards,
R.

Little_G

11:01 am on Sep 14, 2006 (gmt 0)

10+ Year Member



Hi,

You should be able to make adjustments to this script, Updated PHP Bad Bot Script [webmasterworld.com], to do what you want.

Andrew

xcrashorx

4:06 am on Sep 18, 2006 (gmt 0)

10+ Year Member



Sweet thanks guys just looking at the script now....I think this will do it, you guys rock.