Blacklist IPs from viewing your webpage
This is a simple small piece of code that allows you to ban visitors fro viewing your webpage, if you know their ip adresses…
This can be made much more advanced.
With the use of a database such as Mysq (or in some cases just a textfile), you can create a management system for adding, editing and deleting blacklisted ips.
1 2 3 4 5 6 7 8 9 10 11 | <?PHP $ip = $_SERVER['REMOTE_ADDR']; $ban = array( "74.89.41.93", "123.40.1.63", ); if(in_array($ip, $ban)){ die("Sorry, you are banned!"); } ?> |
Explained:
The first line, gets the visitors ip, the second line creates an
array of the blacklisted ip adresses.
The IF statement, checks if the visitors ip is blacklisted, if true, it stops loading
of the webpage and shows the error message.
Usage:
Put the code at the very top of your .php document.
If anyone want a more advanced method to do this (with all the editing and stuff), drop me a comment below :)

Wednesday, July 18th, 2007 at 3:34 am
You should also post your code on 2020code.com to promote your site and your code.
Wednesday, July 18th, 2007 at 5:11 am
Hi! I will take a look at it
the site is in the srart phase right now, but Its going well
thank you for the tip!