首页 > 代码库 > PHP防采集方法代码
PHP防采集方法代码
<?php
/**
* FileName:test.php
* Summary: 防采集
*/
$HTTP_REFERER = $_SERVER["HTTP_REFERER"];
$HTTP_USER_AGENT = $_SERVER["HTTP_USER_AGENT"];
$SERVER_NAME = $_SERVER["SERVER_NAME"];
$CompCharArr =explode(",","Baiduspider,Scooter,ia_archiver,Googlebot,FAST-WebCrawler,MSNBOT,Slurp");
$CompCharArrSize = sizeof($CompCharArr);
$CheckSign = "";
for($i=0;$i<$CompCharArrSize;$i++)
{
$ComChar = trim($CompCharArr[$i]);
if($CompChar<>"" && eregi($CompChar,$HTTP_USER_AGENT))
{
$CheckSign = "T";
}
}
$SERVER_NAME_M = "http://".$SERVER_NAME;//strlen
$EndLenth = strlen($SERVER_NAME_M) + 1;
$CompServerName = "http://".$SERVER_NAME."/";
if(empty($CheckSign) &&($HTTP_REFERER == "" or substr($HTTP_REFERER,0,$EndLenth) <>$CompServerName ))
{
?>
<html>
<body>
<form action=‘ name=checkrefer id=checkrefer method=post></form>
<script>
document.all.checkrefer.action=document.URL;
document.all.checkrefer.submit();
<?php }?>
PHP防采集方法代码