ua识别的作用是可以使得服务器能够识别客户使用的操作系统及版本、cpu 类型、浏览器及版本、浏览器渲染引擎、浏览器语言、浏览器插件,从而判断用户是使用电脑浏览还是手机浏览,让网页作出自动的适应。
ua识别有什么用?
ua识别(浏览器标识识别)可以使得服务器能够识别客户使用的操作系统及版本、cpu 类型、浏览器及版本、浏览器渲染引擎、浏览器语言、浏览器插件,从而判断用户是使用电脑浏览还是手机浏览,让网页作出自动的适应。
可理解为网站通过对ua标示的判别,可按相应的格式进行网页的布局调整,使用户获得更好的浏览体验。
设置成哪个(android、iphone、ipad和电脑)就相当于用哪种设备浏览网页。
以qq手机浏览器为例,介绍查看更改ua标示的方法:
1、打开“手机qq浏览器”,在底部栏中点击中间的按钮,展开菜单列表,选择“设置”。进入设置界面后,就能看到“浏览器ua标识”的设置。
2、打开“浏览器ua标识”,用户就能看到不同的ua标识,有android、iphone、ipad和电脑。如何想把浏览效果变成电脑的话,那么就选择“电脑”。选择完后,输入一个网站查看,原本的手机浏览效果就变回电脑版的浏览效果了。
如果设置成无的话就相当于用电脑浏览器上网,设置成iphone的话就是用iphone上网一样,只是浏览器还是手机的浏览器罢了
精准快速的ua识别php代码
function user_agent($ua) { //开始解析操作系统 $os = null; if (preg_match('/windows nt 6.0/i', $ua)) { $os = "windows vista"; } elseif (preg_match('/windows nt 6.1/i', $ua)) { $os = "windows 7"; } elseif (preg_match('/windows nt 6.2/i', $ua)) { $os = "windows 8"; } elseif (preg_match('/windows nt 6.3/i', $ua)) { $os = "windows 8.1"; } elseif (preg_match('/windows nt 10.0/i', $ua)) { $os = "windows 10"; } elseif (preg_match('/windows nt 5.1/i', $ua)) { $os = "windows xp"; } elseif (preg_match('/mac os x/i', $ua)) { $os = "mac os x"; } elseif (preg_match('#linux#i', $ua)) { $os = "linux "; } elseif (preg_match('#windows phone#i', $ua)) { $os = "windows phone "; } elseif (preg_match('/windows nt 5.2/i', $ua) && preg_match('/win64/i', $ua)) { $os = "windows xp 64 bit"; } elseif (preg_match('/android ([0-9.]+)/i', $ua, $matches)) { $os = "android " . $matches[1]; } elseif (preg_match('/iphone os ([_0-9]+)/i', $ua, $matches)) { $os = 'iphone ' . $matches[1]; } else { $os = '未知操作系统'; } if (preg_match('#(camino|chimera)[ /]([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = 'camino ' . $matches[2]; } elseif (preg_match('#se 2([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = '搜狗浏览器 2' . $matches[1]; } elseif (preg_match('#360([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = '360浏览器 ' . $matches[1]; } elseif (preg_match('#maxthon( |\/)([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = 'maxthon 浏览器' . $matches[2]; } elseif (preg_match('#chrome/([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = 'chrome ' . $matches[1]; } elseif (preg_match('#xiaomi/miuibrowser/([0-9.]+)#i', $ua, $matches)) { $browser = '小米浏览器 ' . $matches[1]; } elseif (preg_match('#safari/([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = 'safari浏览器 ' . $matches[1]; } elseif (preg_match('#opera mini#i', $ua)) { preg_match('#opera/([a-za-z0-9.]+)#i', $ua, $matches); $browser = 'opera mini ' . $matches[1]; } elseif (preg_match('#opera.([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = 'opera ' . $matches[1]; } elseif (preg_match('#tencenttraveler ([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = '腾讯tt浏览器 ' . $matches[1]; } elseif (preg_match('#(ucweb|ubrowser|ucbrowser)/([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = 'uc浏览器 ' . $matches[1]; } elseif (preg_match('#vivaldi/([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = 'vivaldi浏览器 ' . $matches[1]; } elseif (preg_match('#wp-(iphone|android)/([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = 'wordpress客户端 ' . $matches[1]; } elseif (preg_match('#edge ([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = '微软edge浏览器 ' . $matches[1]; } elseif (preg_match('#msie ([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = 'internet explorer ' . $matches[1]; } elseif (preg_match('#(firefox|phoenix|seamonkey|firebird|bonecho|granparadiso|minefield|iceweasel)/([a-za-z0-9.]+)#i', $ua, $matches)) { $browser = 'firefox浏览器 ' . $matches[2]; } else { $browser = '未知浏览器'; } return $os . " | " . $browser;}
更多相关知识,请访问 !!