php禁止采集的方法:1、创建一个PHP示例文件;2、通过“$HTTP_REFERER = $_SERVER["HTTP_REFERER"];$HTTP_USER_AGENT =...”方法实现防采集即可。
php入门到就业线上直播课:进入学习
本文操作环境:Windows7系统、PHP7.1、Dell G3。
php如何实现禁止采集?
PHP防采集方法代码
1 <?php 2 /** 3 * FileName:test.php 4 * Summary: 防采集 5 * Author: sinob 6 * CreateTime: 2005-10-18 7 * LastModifed:2005-10-18 8 * 请参见http://mall.yi85.com/ 9 */ 10 $HTTP_REFERER = $_SERVER["HTTP_REFERER"]; 11 $HTTP_USER_AGENT = $_SERVER["HTTP_USER_AGENT"]; 12 $SERVER_NAME = $_SERVER["SERVER_NAME"]; 13 $CompCharArr = explode(",","Baiduspider,Scooter,ia_archiver,Googlebot,FAST-WebCrawler,MSNBOT,Slurp"); 14 $CompCharArrSize = sizeof($CompCharArr); 15 $CheckSign = ""; 16 for($i=0;$i<$CompCharArrSize;$i++) 17 { 18 $ComChar = trim($CompCharArr[$i]); 19 if($CompChar<>"" && eregi($CompChar,$HTTP_USER_AGENT)) 20 { 21 $CheckSign = "T"; 22 } 23 } 24 $SERVER_NAME_M = "http://".$SERVER_NAME;//strlen 25 $EndLenth = strlen($SERVER_NAME_M) + 1; 26 $CompServerName = "http://".$SERVER_NAME."/"; 27 if(empty($CheckSign) && ($HTTP_REFERER == "" or substr($HTTP_REFERER,0,$EndLenth) <> $CompServerName )) 28 { 29 ?> 30 <html> 31 <body> 32 <form action=' name=checkrefer id=checkrefer method=post></form> 33 <script> 34 document.all.checkrefer.action=document.URL; 35 document.all.checkrefer.submit(); 36 <?php }?>
推荐学习:《PHP视频教程》
以上就是php如何实现禁止采集的详细内容,更多请关注php中文网其它相关文章!
前端(VUE)零基础到就业课程:点击学习
自己动手写 PHP MVC 框架:点击学习
![](http://m.sbmmt.com/img/upload/article/000/000/020/633501a29d313483.png)