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

本文介绍了一个PHP函数,用于判断当前访问者是否为手机用户,并提供了一个链接允许查看HTTP_USER_AGENT信息及远程IP地址。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<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="/" οnclick="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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值