NameSilo

(PHP) Ban Ip From Your Site

Spaceship Spaceship
Watch
R

Romance Of Love

Guest
Guest
It is one of the effective code for banning the IP address from your website.
Just paste the codeinto your PHP page.


PHP:
<?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.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
0
•••
You may also want to use array() funtion in your code to use more then one ip address.
 
0
•••
PHP:
$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...
 
0
•••
you should also check $_SERVER['X_FORWARDED_FOR'] in case they are using a proxy (although some proxies hide both)
 
0
•••
Enter the IP into 'hosts.deny'?
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back