FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP IP Ban





puccavn
1. What it does

IP banning someone from your site will effectivly stop all access they have to your website. Make sure you ban wisely

2. The Code

The code is fairly simple, we will set the $banned variable using an array. It is here were we will enter IP address we wish to ban. Then, using the global variable $REMOTE_ADDR to give us the user's IP address, we can check if it is in the $banned array. If not, we let them carry on. If it is found in the $banned array, using the die() fuction, we can remove all access to the site from that IP.

<?php
$banned = array("1.1.1.1", "2.2.2.2", "3.3.3.3");
(in_array("$REMOTE_ADDR", $banned_addresses)) {
die("You have been banned from this site");
}
?>

3. Adding the ban filter

Save the above into ban.php or similar, then include it on all the pages you want it to be effective on, using the include() fuction.

Please contact us if you enjoyed this tutorial, or find any typos, etc
foggy
The code is wrong, the variable names do not match. Use this code instead, it's the exact same with one change that will make it work.
Code:
<?php
$banned_addresses = array("1.1.1.1", "2.2.2.2", "3.3.3.3");
(in_array("$REMOTE_ADDR", $banned_addresses)) {
die("You have been banned from this site");
}
?>
puccavn
sorry
fix the var name Very Happy
assaultdk
Thanks foggy!
Related topics
better hosting system
ip looking
Ip Banning Using Php
users online, using php and text file
Help Me!!!
php error ?[parse error]
IP Address Banning ( Not using .htaccess)
IP Banning...
IP Ban
Proxy Checker or IP BAN
mysql gives the wrong result [solved]
making a site but I need help I am new to php and Runy scrip
need IP blocker on my site
PHP IP tracking script ?
Reply to topic    Frihost Forum Index -> Miscellaneous -> Tutorials

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.