php实现封IP功能

早起一起突然看到,我的网站有人在恶心乱搞,为了防止这种事情我想了一个办法那就是封用户的IP了.首页我们来建数据库:

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

下页来创建一个封文件的页面,主要是用户写入IP以"|"分开,这个页面就不多写了,我就简单的写一下,入库代码$UlockIp=$_POST['z']?$_POST['z']:''; 

  1. if(emptyempty($UlockIp)){ 
  2.   exit("<script>alert('对不起,你输入的信息有误!');history.back();</script>"); 
  3.  } 
  4.  $sql="update su_lockip set lockip='$UlockIp'"
  5.  if(mysql_query($sql)){ 
  6.   exit("<script>alert('锁定成功!');history.back();</script>"); 
  7.  }else
  8.   exit("<script>alert('对不起,你输入的信息有误!');history.back();</script>"); 
  9.  } 

就这么简单,最后就是进行锁定的了.下面代码是根据数据中是否存用户IP,如果在就提示被KILL了.代码如下:

  1. function lock_user_ip(){ 
  2.  $Usql =mysql_query("select * from su_lockip"); 
  3.  $Urs =mysql_fetch_array($Usql); 
  4.  $UlockIp=$Urs['lockip']; 
  5.  $ClockIp=$this->get_real_ip(); 
  6.  $Iplist =explode('|',$UlockIp); 
  7.  if(in_array($ClockIp,$Iplist)){ 
  8.   exit('sorry system lock your IP'); 
  9.  } 
  10.  } 
  11.  
  12.  function get_real_ip(){//这段代码来是互联网. 
  13.    $ip=false; 
  14.    if(!emptyempty($_SERVER["HTTP_CLIENT_IP"])){ 
  15.     $ip = $_SERVER["HTTP_CLIENT_IP"]; 
  16.    } 
  17.    if (!emptyempty($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
  18.     $ips = explode (", "$_SERVER['HTTP_X_FORWARDED_FOR']); 
  19.     if ($ip) { array_unshift($ips$ip); $ip = FALSE; } 
  20.     for ($i = 0; $i < count($ips); $i++) { 
  21.      if (!eregi ("^(10|172.16|192.168)."$ips[$i])) { 
  22.       $ip = $ips[$i]; 
  23.       break
  24.      } 
  25.     } 
  26.    } 
  27.    return ($ip ? $ip : $_SERVER['REMOTE_ADDR']); 
  28.  } 

哈哈写完了就这么简单,没有进行安全过滤处理.

波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » php实现封IP功能

81 评论

  1. order tadalafil 5mg pill buy tadalafil 20mg viagra next day delivery usa

  2. order olmesartan 20mg pill brand olmesartan acetazolamide 250mg generic

  3. order bupropion 150mg online cheap order strattera sale buy seroquel 100mg without prescription

  4. order luvox generic brand cymbalta buy glipizide 10mg generic

  5. cialis next day cialis oral purchase sildenafil without prescription

  6. write essay for money play casino online blackjack vegas free online games

  7. order clomid 50mg online cheap order clomid 50mg gamble poker online

  8. buy allopurinol for sale zetia uk zetia 10mg without prescription

  9. tadalafil 40mg price ampicillin us ciprofloxacin ca

  10. sildenafil dosage sildalis generic lamotrigine over the counter

  11. buy generic deltasone 10mg accutane cheap cheap amoxicillin tablets

  12. order albuterol 100 mcg without prescription protonix brand ciprofloxacin 1000mg ca

  13. buy cialis 5mg pills cialis coupon tadalafil us

  14. buy generic diamox buy diamox pill azathioprine 50mg sale

发表评论

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡