Tips

  • 检查浏览器是否是Firefox或Chrome
		$agent = $_SERVER["HTTP_USER_AGENT"];//浏览器类型
		$flag = strpos($agent,"Firefox");
		$flag_m = strpos($agent, "Chrome");
		if(!$flag && !$flag_m){
			$this->show('public/notice.php');
			die();
		}<pre name="code" class="php">function checkUrl($url){
	    $header = get_headers($url, 1);//获取有信息
	    if(preg_grep('/200/', $header)){
	        return true;
	    }
	    return false;
	}

 

  • 判断是否是蜘蛛在访问
function isspider(){
		$robots = array("baiduspider","googlebot","sosospider","360spider","slurp","yodaobot","sogou","msnbot","bingbot");
		$is_spider = false;
		$agent = strtolower($_SERVER["HTTP_USER_AGENT"]);//获取访问者浏览器相关参数
		foreach($robots as $user_agent){
			if(ereg($user_agent,$agent)){
				$is_spider=true;
			}
		}
		return $is_spider ;
	}


  • 校验URL是否404
function checkUrl($url){
	    $header = get_headers($url, 1);//获取有信息
	    if(preg_grep('/200/', $header)){
	        return true;
	    }
	    return false;
	}
附header的内容如:

Array
(
    [0] => HTTP/1.1 200 OK
    [Date] => Sat, 15 Aug 2015 01:28:23 GMT
    [Server] => Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
    [X-Powered-By] => PHP/5.3.1
    [Set-Cookie] => PHPSESSID=us51gi7nua9hq6p16elcukg067; path=/; domain=t.youai.com
    [Expires] => Thu, 19 Nov 1981 08:52:00 GMT
    [Cache-Control] => no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    [Pragma] => no-cache
    [Connection] => close
    [Content-Type] => text/html; charset=utf-8
)























  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值