什么是检测用PHP浏览器的最佳方式? [英] What's the best way to detect a browser with php?

查看:84
本文介绍了什么是检测用PHP浏览器的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我使用PHP来检测浏览器的最佳方式? IE 6和7是可怕的,当涉及到实现用CSS完全浏览器兼容,所以我的网站是不会支持和IE的版本是早于8。

Could anyone tell me the best way to detect a browser using php? IE 6 and 7 are terrible when it comes to achieving full browser compatibility with CSS so my site isn't going to support and version of IE that's older than 8.

我是用电流 $ _ SERVER ['HTTP_USER_AGENT'] 来检测浏览器,但我被告知,这是不这样做,因为一个好办法浏览器可以撒谎,发送他们想要的任何用户代理的信息。因此,没有人知道一个确保消防方式来检测客户端使用的浏览器类型?

I'm current using $_SERVER['HTTP_USER_AGENT'] to detect the browser but I've been told that that isn't a good way to do it since browsers can lie and send any user agent info that they want. So, does anyone know of a sure fire way to detect the type of browser that the client is using?

推荐答案

您不能可靠地检测浏览器是什么。它的那样简单。

You can't reliably detect what the browser is. Its as simple as that.

浏览器能够谎报自己的身份,并经常做的。

Browsers are capable of lying about their identity, and frequently do.

有些代理服务器和安全产品的要求剥离用户代理的数据,所以你的PHP code可能只是得到一个空字符串。

Some proxies and security products strip the user agent data from the request, so your PHP code may just get an empty string.

在Javascript中,你可能有更多的一点点运气,但它仍然是有问题的,但在PHP层你永远无法真正肯定。

In Javascript you may have a bit more luck, though it's still problematic, but at the PHP level you can never really be certain.

我的第一个建议是放弃支持IE6,除非你的人口是真正stubbon少数。 IE6使用情况统计下降到低于大多数发达国家2.5%的现在。这本身将摆脱你的CSS问题的很大一部分。 IE7仍然不好,但它是一个明确英里比IE6更好,而坚持现代标准也只是支持的。

My first suggestion would be to drop support for IE6, unless your demographic is in the really stubbon minority. IE6 usage stats is down to below 2.5% in most developed countries now. That alone will get rid of a large part of your CSS problems. IE7 is still not good, but it's a clear mile better than IE6, and it is just about supportable while sticking to modern standards.

我的第二个建议是,而不是试图降级您的站点为这些浏览器,尝试升级浏览器。

My second suggestion is rather than trying to downgrade your site for these browsers, try to upgrade the browser.

有一些很好的黑客和工具,让您提高旧版本的IE的CSS支持。我建议你​​尝试以下方法:

There are a number of very good hacks and tools that will allow you to improve CSS support in older versions of IE. I recommend you try the following:

  • CSS3Pie
  • Selectivizr
  • Modernizr
  • Dean Edwards' IE7.js

当然,无处不在的 JQuery的

这篇关于什么是检测用PHP浏览器的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆