欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php如何实现禁止采集

程序员文章站 2022-03-07 19:59:13
...

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