您的位置:首页 > 编程语言 > PHP开发

php检测客户端是手机还是电脑

2012-11-14 00:01 423 查看
<div style="margin:150px auto;text-align:center;border:1px dashed #f00;width:240px;padding:25px 5px;">

<?php

function is_mobile(){

$regExp="/nokia|iphone|android|samsung|htc|motorola|blackberry|ericsson|huawei|dopod|amoi|gionee|^sie\-|^bird|^zte\-|haier|";

$regExp.="blazer|netfront|helio|hosin|novarra|techfaith|palmsource|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|";

$regExp.="symbian|smartphone|midp|wap|phone|windows ce|CoolPad|webos|iemobile|^spice|longcos|pantech|portalmmm|";

$regExp.="alcatel|ktouch|nexian|^sam\-|s[cg]h|^lge|philips|sagem|wellcom|bunjalloo|maui|";

$regExp.="jig\s browser|hiptop|ucweb|ucmobile|opera\s*mobi|opera\*mini|mqqbrowser|^benq|^lct";

$regExp.="480×640|640x480|320x320|240x320|320x240|176x220|220x176/i";

if(!isset($_SERVER['HTTP_USER_AGENT'])){

return true;

}else{

return @$_GET['mobile'] || isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE']) || preg_match($regExp, strtolower($_SERVER['HTTP_USER_AGENT']));

}

}

?>

<input value="<?php echo '您是'.(is_mobile()? '手机' : '电脑').'用户';?>" readonly /><br />

<a href="/" onclick="alert('<?php echo $_SERVER['HTTP_USER_AGENT'].'\r\nIP:'.$_SERVER['REMOTE_ADDR']; ?>');return false;">查看UA信息</a> <a href='http://www.qsyz.net/'>返回首页</a>

</div>


转自http://www.qsyz.net/t-3953-1-1.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: