PHP Code

Ban visitors based on IP address with PHP

Most web hosting control panels allow you to ban IP addresses or ranges from your website. But if you don't have that capability provided by your host, here's the simple way to enable this through PHP:

$banip = array('127.0.0.1','127.0.0.2','127.0.0.3');

$ip = $_SERVER['REMOTE_ADDR'];

for($i=0;$i<3;$i++){ if($ip == $banip[$i]) { echo "You are currently banned from this website, sorry!"; die(); } else { // carry on with site rendering } } [/code]

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image