- 检查浏览器是否是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
)