Rumah > pembangunan bahagian belakang > tutorial php > php 怎么获取浏览器的类型?

php 怎么获取浏览器的类型?

WBOY
Lepaskan: 2016-06-06 20:33:05
asal
1225 orang telah melayarinya

php 怎么获取访问访问页面的浏览器类型,包括客户端和浏览器类型

回复内容:

php 怎么获取访问访问页面的浏览器类型,包括客户端和浏览器类型

github上有现成的开源项目可以参考下:
比如:cbschuld的这个Browser项目,支持识别以下浏览器:

Opera Browser::BROWSER_OPERA
WebTV Browser::BROWSER_WEBTV NetPositive Browser::BROWSER_NETPOSITIVE
Internet Explorer Browser::BROWSER_IE Pocket Internet Explorer
Browser::BROWSER_POCKET_IE Galeon Browser::BROWSER_GALEON Konqueror
Browser::BROWSER_KONQUEROR iCab Browser::BROWSER_ICAB OmniWeb
Browser::BROWSER_OMNIWEB Phoenix Browser::BROWSER_PHOENIX Firebird
Browser::BROWSER_FIREBIRD Firefox Browser::BROWSER_FIREFOX Mozilla
Browser::BROWSER_MOZILLA Amaya Browser::BROWSER_AMAYA Lynx
Browser::BROWSER_LYNX Safari Browser::BROWSER_SAFARI iPhone
Browser::BROWSER_IPHONE iPod Browser::BROWSER_IPOD Google’s Android
Browser::BROWSER_ANDROID Google’s Chrome Browser::BROWSER_CHROME
GoogleBot Browser::BROWSER_GOOGLEBOT Yahoo!’s Slurp
Browser::BROWSER_SLURP W3C’s Validator Browser::BROWSER_W3CVALIDATOR
BlackBerry Browser::BROWSER_BLACKBERRY

print_r($_SERVER['HTTP_USER_AGENT']);

php中有一个$_SERVER['HTTP_USER_AGENT']能获取到浏览器和操作系统的信息,如在我自己的电商上输出的是:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36

从这个里面就能分析出当前用户使用的浏览器内核、浏览器版本和操作系统等信息

区分移动设备和pc访问站点

可以试下 php 自带函数
get_browser(null);
返回类似

<code>Array
(
    [browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$
    [browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*
    [parent] => Firefox 0.9
    [platform] => WinXP
    [browser] => Firefox
    [version] => 0.9
    [majorver] => 0
    [minorver] => 9
    [cssversion] => 2
    [frames] => 1
    [iframes] => 1
    [tables] => 1
    [cookies] => 1
    [backgroundsounds] =>
    [vbscript] =>
    [javascript] => 1
    [javaapplets] => 1
    [activexcontrols] =>
    [cdf] =>
    [aol] =>
    [beta] => 1
    [win16] =>
    [crawler] =>
    [stripper] =>
    [wap] =>
    [netclr] =>
)
</code>
Salin selepas log masuk

使用get_browser() 参考手册链接

<code>$browser = get_browser(null, true);
print_r($browser);
</code>
Salin selepas log masuk
Label berkaitan:
php
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan