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('','','');


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]


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