还有另一种根本不需要 php 的方法,它是条件注释:
<!--[if IE]>
<?php echo "User is using Internet Explorer"; ?>
<![endif]-->
<!--[if IE 6]>
<?php echo "User is using Internet Explorer 6"; ?>
<![endif]-->
ETC...
如果资源管理器是 IE 并且版本小于或大于 X,您也可以获得:
Code if User uses IE and it's below version 9
Code if User uses IE and it's below than or equal to version 7
Code if User uses IE and it's greater than version 6
The advantages are that you can also pick the version of the browser, easy to implement, and you are using a little less resources from your server xD (although it would be a insignificant difference).
Another advantage is that you can use that to include css or js files in the header of your page depending on the browser.
The disadvantage is that you has less control as it's browser based(client side).