What's the best way to detect a browser with php?

后端 未结 5 953
我在风中等你
我在风中等你 2021-01-21 08:13

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 t

5条回答
  •  执念已碎
    2021-01-21 08:57

    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.

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

    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.

    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.

    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

    And of course, the ubiquitous JQuery.

提交回复
热议问题