logo
当前位置:首 页 > 编程技术 >服务器语言 >PHP语言 > 查看文章

放在php网站的入口文件,判断是否是手机或者pad的登陆的,使用的是浏览器代理技术,这个技术还是蛮可靠的。

不过有的时候,会被有的浏览器的自定义代理欺骗。例如使用小米自带的浏览器,就有一个浏览器识别设置的,我使用了下,所有国内和大部分国外的网站都被欺骗了,可以说,现在判断浏览器代理的技术还是主流,有的网站还有区分

pad和手机,这个只要将下面的“$mobile_agents字段的部分pad的识别标志分开在写个函数就好了;

 

//判断是否属手机

function is_mobile() {
	$user_agent = $_SERVER['HTTP_USER_AGENT'];
	$mobile_agents = Array("240x320","acer","acoon","acs-","abacho","ahong","airness",
"alcatel","amoi","android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus",
"audio","au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu",
"cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly ","fly_",
"fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi","htc","huawei",
"hutchison","inno","ipad","ipaq","ipod","jbrowser","kddi","kgt","kwc","lenovo","lg ","lg2",
"lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo","mercator","meridian",
"micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen",
"nexian","nf-browser","nintendo","nitro","nokia","nook","novarra","obigo","palm","panasonic",
"pantech","philips","phone","pg-","playstation","pocket","pt-","qc-","qtek","rover","sagem",
"sama","samu","sanyo","samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens",
"sie-","softbank","sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-",
"teleca","telit","tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool",
"virgin","vk-","voda","voxtel","vx","wap","wellco","wig browser","wii","windows ce",
"wireless","xda","xde","zte");
	$is_mobile = false;
	foreach ($mobile_agents as $device) {
		if (stristr($user_agent, $device)) {
			$is_mobile = true;
			break;
		}
	}
	return $is_mobile;
}
//使用很简单
if( is_mobile() ){
Your Code
}
一个有大大梦想但是没有支撑这梦想的技术的攻城狮,大家就当这个博客是你的技术工具箱吧,我会吧我工作中遇到的问题贴在这,大家需要的记得把我放到收藏夹哦! 百度输入“子傲代码”就可以了

—— 陈子傲

admin
你可能也喜欢Related Posts
众说纷纭Comments
大眼 可爱 大笑 坏笑 害羞 发怒 折磨 快哭了 大哭 白眼 晕 流汗 困 腼腆 惊讶 憨笑 色 得意 骷髅 囧 睡觉 眨眼 亲亲 疑问 闭嘴 难过 淡定 抗议 鄙视 猪头
小提示:直接粘贴图片到输入框试试
努力发送中...
footer logo
未经许可请勿自行使用、转载、修改、复制、发行、出售、发表或以其它方式利用本网站之内容
Copyright ©ziao design Studio All Rights Reserved.沪ICP备14052271号-3