PHP detect Internet Explorer that is below version

2019-02-24 09:52发布

问题:

Could someone do this for me? As I only have macs and cannot test IE.

What's a good way of running an event IF the browser is Internet Explorer, and the version is under 10. So say it's IE 7, it will show the error, or if it's IE 9.9, it will show the error, however if it's IE 10, 10.1, 10.0.1 etc it will not show the error.

回答1:

The function get_browser() may be used for feature detection.

If you really want to only know the user's browser version you can look at the $_SERVER['HTTP_USER_AGENT'].

A word of caution: although most users won't do this, it is possible to send a different user agent string to the server which might be done to e.g. protect ones privacy. If someone wants to go as far as sending you a user agent to be able to use your website though they'll probably know how to deal with any bugs that may come up.

As a side question, what is the reason you're trying to limit your audience to IE 10 and up? Why not use a library such as Modernizr to fill in functions you might be missing in IE 9?

EDIT: Some info regarding the IE 10 user agent string. You will want to read that so you know what to match your $_SERVER['HTTP_USER_AGENT'] against



回答2:

Come on, try to search next time ;-)
It's always recommended way of asking

Can I detect IE6 with PHP?
Detecting IE browser version using PHP
PHP get_browser: how to identify ie7 versus ie6?
PHP: If internet explorer 6, 7, 8 , or 9



回答3:

PHP's get browser method will return the user agent string. All IE 10 browsers will contain MSIE 10.0 in this user agent.