首页
> 计算机技术
> 后端开发
> PHP
PHP语言中如何判断请求是来自电脑还是手机的方法
原创 lihf8515 2025年02月20日 20:10
来源:本站 阅读:438
PHP语言中如何判断请求是来自电脑还是手机的方法,主要是通过$_SERVER['HTTP_USER_AGENT']变量中所包含的值的情况做出判断。具体实现函数如下://判断客户端是否手机functionis_mobile(){$agent=empty($_SERVER['HTTP_USER_AGENT'])?'未知':$_SERVER['HTTP_USER_AGENT'];if(preg_match('/nokia/i',$agent)||preg_match('/sony/i',$agent)||preg_match('/ericsson/i',$agent)||preg_match('/mot/i',$agent)||preg_match('/samsung/i',$agent)||preg_match('/htc/i',$agent)||preg_match('/sgh/i',$agent)||preg_match('/lg/i',$agent)||preg_match('/blackberry/i',$agent)||preg_match('/meizu/i',$agent)||preg_match('/sharp/i',$agent)||preg_match('/sie-/i',$agent)||preg_match('/philips/i',$agent)||preg_match('/panasonic/i',$agent)||preg_match('/alcatel/i',$agent)||preg_match('/lenovo/i',$agent)||preg_match('/iphone/i',$agent)||preg_match('/ipod/i',$agent)||preg_match('/netfront/i',$agent)||preg_match('/symbian/i',$agent)||preg_match('/ucweb/i',$agent)||preg_match('/windowsce/i',$agent)||preg_match('/palm/i',$agent)||preg_match('/operamini/i',$agent)||preg_match('/operamobi/i',$agent)||preg_match('/operamobi/i',$agent)||preg_match('/openwave/i',$agent)||preg_match('/nexusone/i',$agent)||preg_match('/cldc/i',$agent)||preg_match('/midp/i',$agent)||preg_match('/wap/i',$agent)||preg_match('/andorid/i',$agent)||preg_match('/mobile/i',$agent)){$os=1;}else{$os=0;}return$os;}……
浏览全文,请先 登录
浏览全文,请先 登录
作者
昵称:君子如兰
注册时间:2025-01-31 02:47:34
最近更新:2025-12-29 15:35:31
文章总数:92篇
原创 86篇
转载 6篇
皖公网安备34130202000765号