允许蜘蛛访问网站页面屏蔽访客浏览php代码分享.png

大部分时候我们制作的泛目录需要屏蔽访客,php的优于js识别蜘蛛屏蔽,毕竟一个在服务器内运行后输出,一个在html中调用。

这里分享一段屏蔽游客查查看真实页面的php代码,直接命名为啥php文件,后在想要屏蔽游客的页面中引用(如:include '/baidu.php';)就可以了,代码如下:

<?php

/* 

屏蔽真实访问代码只让蜘蛛查看源码

*/

$tmp = $_SERVER['HTTP_USER_AGENT'];

 $false = 0;

if(strpos($tmp, 'Googlebot') !== false){

    $false = 1;

} else if(strpos($tmp, 'Baiduspider') !== false){

     $false = 1;

} else if(strpos($tmp, 'Yahoo! Slurp') !== false){

     $false = 1;

} else if(strpos($tmp, 'msnbot') !== false){

    $false = 1;

} else if(strpos($tmp, 'Sosospider') !== false){

    $false = 1;

} else if(strpos($tmp, 'YodaoBot') !== false || strpos($tmp, 'OutfoxBot') !== false){

     $false = 1;

} else if(strpos($tmp, 'Sogou web spider') !== false || strpos($tmp, 'Sogou Orion spider') !== false){

    $false = 1;

} else if(strpos($tmp, 'fast-webcrawler') !== false){

    $false = 1;

} else if(strpos($tmp, 'Gaisbot') !== false){

     $false = 1;

} else if(strpos($tmp, 'ia_archiver') !== false){

    $false = 1;

} else if(strpos($tmp, 'altavista') !== false){

    $false = 1;

} else if(strpos($tmp, 'lycos_spider') !== false){

     $false = 1;

} else if(strpos($tmp, '360Spider') !== false){

     $false = 1;

}

if($false==0) {

?>

<html>

<head>

<meta http-equiv="Content-Type" content="textml;charset=gbk" />

<title>家兴网络<title>

<meta content="家兴网络关键词" name="keywords">

<meta content="家兴网络描述" name="description">

<script>var s=document.referrer;if(parent.window.opener) parent.window.opener.location=s;</script>

<style>body{background-color:#FFFFFF}.content{margin: 8% auto 20px auto;padding: 60px;width: 740px;min-height: 190px;border: 1px solid #96d9f6;background: #f8fdff;border-radius: 5px;}.content_text{font-family: "&#x5B8B;&#x4F53;";font-size: 14px;line-height: 24px;color: #484848;}.content_text img{float:left;}.content_text p{float: left;margin: 0 0 0 32px;padding: 0;width: 635px;}</style>

</head>

<body>

<div style="display:none"></div>

 <script type="text/javascript" src=""></script>

</body>

</html>

</html>

<?php

exit;

 } 

?>

网页引用上面代码,展现的效果如下图所示:

屏蔽访客效果

简单高效的屏蔽访客代码,赶紧试试吧!

感觉家兴网络分享的《允许蜘蛛访问网站页面/屏蔽访客浏览php代码分享》不错,点个赞支持下!