How to usp php to ban ip

First build a database table:

CREATE TABLE `su_lockip` (
  `id` int(4) NOT NULL auto_increment,
  `lockip` varchar(1024) default NULL,
  PRIMARY KEY  (`id`)
) 

Second, design a page so that you can add the ip you want to ban, every ip is devided by |,  I only write the mail part:
 

$UlockIp=$_POST[‘z’]?$_POST[‘z’]:”;
 if(empty($UlockIp)){
  exit(“<script>alert(‘Sorry, the message your input is wrong!’);history.back();</script>”);
 }
 $sql=”update su_lockip set lockip=’$UlockIp'”;
 if(mysql_query($sql)){
  exit(“<script>alert(‘Locked succesfully!’);history.back();</script>”);
 }else{
  exit(“<script>alert(‘Sorry, the message your input is wrong!’);history.back();</script>”);
 } 

Last, check the ip is in the database or not, if in the database, then show killed.

function lock_user_ip(){
 $Usql =mysql_query(“select * from su_lockip”);
 $Urs =mysql_fetch_array($Usql);
 $UlockIp=$Urs[‘lockip’];
 $ClockIp=$this->get_real_ip();
 $Iplist =explode(‘|’,$UlockIp);
 if(in_array($ClockIp,$Iplist)){
  exit(‘sorry system lock your IP’);
 }
 }
 
 function get_real_ip(){
   $ip=false;
   if(!empty($_SERVER[“HTTP_CLIENT_IP”])){
    $ip = $_SERVER[“HTTP_CLIENT_IP”];
   }
   if (!empty($_SERVER[‘HTTP_X_FORWARDED_FOR’])) {
    $ips = explode (“, “, $_SERVER[‘HTTP_X_FORWARDED_FOR’]);
    if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
    for ($i = 0; $i < count($ips); $i++) {
     if (!eregi (“^(10|172\.16|192\.168)\.”, $ips[$i])) {
      $ip = $ips[$i];
      break;
     }
    }
   }
   return ($ip ? $ip : $_SERVER[‘REMOTE_ADDR’]);
 }Â