2011年4月1日 星期五

Determine the capabilities of the user's browser‏

Determine the capabilities of the user's browser‏ by using the $_SERVER['HTTP_USER_AGENT'].


strpos($_SERVER['HTTP_USER_AGENT'], $keyword);

IE6: $keyword = 'MSIE 6';
IE7: $keyword = 'MSIE 7';
IE8: $keyword = 'MSIE 8';
IE9: $keyword = 'MSIE 9';
..etc

IE11起不會再出現關鍵字MSIE,改用Trident代替,
ex:
Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko

Firefox 3.6: $keyword = 'Firefox/3.6.';
Firefox 4.0: $keyword = 'Firefox/4.0.';
...etc

Opera: $keyword = 'Opera';



Both Google Chrome and Apple Safari browser's information in browscap.ini file, has the same keyword, named "Safari"! So you have to determine whether the keyword "Chrome" exist or not, after determining the existence of the "Safari" one.


Chrome 10.0: $keyword = 'Chrome/10.0.';

And the information of the Google Chrome browser's browscap.ini goes something like this:

Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16

沒有留言:

張貼留言