国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php網(wǎng)站防止刷流量攻擊方法

2024-05-04 21:58:47
字體:
供稿:網(wǎng)友

流量攻擊是一種比較初級的網(wǎng)站攻擊方法,就是不停的去刷樣網(wǎng)站,導(dǎo)致服務(wù)器處理不過來或數(shù)據(jù)庫負(fù)載不了,導(dǎo)致網(wǎng)站無法正常方法的一種攻擊手段了,下面我來介紹一個利用php防網(wǎng)站刷流量攻擊方法.

php網(wǎng)站防止刷流量攻擊方法實例代碼如下:

  1. <?php 
  2. //查詢禁止IP 
  3. $ip =$_SERVER['REMOTE_ADDR']; 
  4. $fileht=".htaccess2"
  5. if(!file_exists($fileht))file_put_contents($fileht,""); 
  6. $filehtarr=@file($fileht); 
  7. if(in_array($ip."rn",$filehtarr))die("Warning:"."<br>"."Your IP address are forbided by some reason, IF you have any question Pls emill to shop@mydalle.com!"); 
  8.  
  9. //加入禁止IP 
  10. $time=time(); 
  11. $fileforbid="log/forbidchk.dat"
  12. if(file_exists($fileforbid)) 
  13. if($time-filemtime($fileforbid)>60)unlink($fileforbid); 
  14. else
  15. $fileforbidarr=@file($fileforbid); 
  16. if($ip==substr($fileforbidarr[0],0,strlen($ip))) 
  17. if($time-substr($fileforbidarr[1],0,strlen($time))>600)unlink($fileforbid); 
  18. elseif($fileforbidarr[2]>600){file_put_contents($fileht,$ip."rn",FILE_APPEND);unlink($fileforbid);} 
  19. else{$fileforbidarr[2]++;file_put_contents($fileforbid,$fileforbidarr);} 
  20. //防刷新 
  21. $str=""
  22. $file="log/ipdate.dat"
  23. if(!file_exists("log")&&!is_dir("log"))mkdir("log",0777); 
  24. if(!file_exists($file))file_put_contents($file,""); 
  25. $allowTime = 120;//防刷新時間 
  26. $allowNum=10;//防刷新次數(shù) 
  27. $uri=$_SERVER['REQUEST_URI']; 
  28. $checkip=md5($ip); 
  29. $checkuri=md5($uri); 
  30. $yesno=true; 
  31. $ipdate=@file($file); 
  32. foreach($ipdate as $k=>$v
  33. $iptem=substr($v,0,32); 
  34. $uritem=substr($v,32,32); 
  35. $timetem=substr($v,64,10); 
  36. $numtem=substr($v,74); 
  37. if($time-$timetem<$allowTime){ 
  38. if($iptem!=$checkip)$str.=$v
  39. else
  40. $yesno=false; 
  41. if($uritem!=$checkuri)$str.=$iptem.$checkuri.$time."1rn"
  42. elseif($numtem<$allowNum)$str.=$iptem.$uritem.$timetem.($numtem+1)."rn"
  43. else 
  44. if(!file_exists($fileforbid)){$addforbidarr=array($ip."rn",time()."rn",1);file_put_contents($fileforbid,$addforbidarr);} 
  45. file_put_contents("log/forbided_ip.log",$ip."--".date("Y-m-d H:i:s",time())."--".$uri."rn",FILE_APPEND); 
  46. $timepass=$timetem+$allowTime-$time
  47. die("Warning:"."<br>"."Sorry,you are forbided by refreshing frequently too much, Pls wait for ".$timepass." seconds to continue!"); 
  48. }//開源代碼Vevb.com 
  49. if($yesno$str.=$checkip.$checkuri.$time."1rn"
  50. file_put_contents($file,$str); 
  51. ?> 

利用session 跟蹤防post提交,代碼如下:

  1. <?php  
  2. session_start();  
  3. $clean = array();  
  4. $email_pattern = '/^[^@s<&>]+@([-a-z0-9]+.)+[a-z]{2,}$/i';  
  5. if (preg_match($email_pattern$_POST['email']))  
  6. {  
  7. $clean['email'] = $_POST['email'];  
  8. $user = $_SESSION['user'];  
  9. $new_password = md5(uniqid(rand(), TRUE));  
  10. if ($_SESSION['verified'])  
  11. {  
  12. /* Update Password */  
  13. mail($clean['email'], 'Your New Password'$new_password);  
  14. }  
  15. }  
  16. ?> 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 大荔县| 交城县| 永泰县| 喀喇沁旗| 都匀市| 咸阳市| 铜川市| 保亭| 雅安市| 衢州市| 阿勒泰市| 阳春市| 平阴县| 蒲城县| 托克逊县| 岚皋县| 孝义市| 辛集市| 星子县| 饶平县| 定结县| 阜阳市| 武夷山市| 荣昌县| 兰州市| 马尔康县| 红河县| 信宜市| 花莲市| 高台县| 鹿邑县| 鲁山县| 台安县| 紫阳县| 历史| 启东市| 淮北市| 平和县| 青冈县| 公主岭市| 抚宁县|