I’m looking to try and block access from two IP addresses in PHP, preferably notifying them of their blocking.
Is there anyway I can do this or is it just not possible using PHP?
I’ve seen a JavaScript version of doing it, but if the browser has JavaScript turned off, then surely they’d be able to get around it.
Thanks for any advice/help in advance.
in index.php:
Or this version, which becomes more manageable when you start having more than one or two bans:
Take a look at this page. It contains a function for getting a client’s IP address. You can call this on any page and if the IP address matches then display an error message.
However an easier solution is to use
.htaccess
Add the following lines to
.htaccess
Where xxx are the IP number you wish to block.
$_SERVER[‘REMOTE_ADDR’] should contain the IP.
One place to block is on the web server. Then only allowed IPs would even make it to your site and you wouldn’ty have to introduce any special handling code.
See http://www.iphowto.com/Block_IP_How_To.aspx