软件开发者和爱好者的知识分享社区
关于本站 登录 注册
首页 > 计算机技术 > 后端开发 > 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;}……

浏览全文,请先 登录
友情链接: 海峰收银系统  
Copyright © 2025 HF软件技术. All Rights Reserved.
中华人民共和国工业和信息化部ICP备案序号:皖ICP备2025073039号