NamePros.Com (http://www.namepros.com/)
-   CODE (http://www.namepros.com/code/)
-   -   (PHP) Ban Ip From Your Site (http://www.namepros.com/code/383996-php-ban-ip-from-your-site.html)

Romance Of Love 10-12-2007 08:30 AM

(PHP) Ban Ip From Your Site
 
It is one of the effective code for banning the IP address from your website.
Just paste the codeinto your PHP page.


PHP Code:
<?php
// This will retrieve ip!
$ip = getenv('REMOTE_ADDR');
// Replace 'x' with ip address!
$blocked = "xx.xx.xx.xx";

if (
ereg($blocked,$ip))
{
echo
"You Have Been Banned";
exit();
}
?>
'echo "You Have Been Banned";'


this is the message which will be displayed when the banned ip goes on the page. Remember to swap the x's with the IP you wish to ban.

asgsoft 10-20-2007 03:26 AM

nice tutorial

may I share http://www.thewebmasterstool.com/tu...g-on-your-site/ which is slightly more advanced as it uses MySQL but does the same job

NetworkTown.Net 11-20-2007 09:41 AM

You may also want to use array() funtion in your code to use more then one ip address.

Daniel 11-21-2007 08:39 AM

PHP Code:
$ips = array("1.2.3.4", "2.3.4.5");

if(
in_array($_SERVER['REMOTE_ADDR'],$ips))
{
    
header("HTTP/1.0 403 Forbidden");
    die(
"Your IP has been banned.");
}


Untested...

Peter 11-21-2007 09:02 AM

you should also check $_SERVER['X_FORWARDED_FOR'] in case they are using a proxy (although some proxies hide both)

aZooZa 11-30-2007 11:21 AM

Enter the IP into 'hosts.deny'?


All times are GMT -7. The time now is 06:36 PM.
Site Sponsors
Advertise your business at NamePros

Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0