Home >Backend Development >PHP Tutorial >php detect browser type code

php detect browser type code

WBOY
WBOYOriginal
2016-07-25 08:43:09778browse
  1. // Simple browser detection
  2. $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = false;
  3. if (strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false) {
  4. $is_lynx = true;
  5. } elseif ( strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'chrome') !== false ) {
  6. $is_chrome = true;
  7. } elseif ( strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'webkit') !== false ) {
  8. $is_safari = true;
  9. } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false) {
  10. $is_gecko = true;
  11. } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false) {
  12. $is_winIE = true;
  13. } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) {
  14. $is_macIE = true;
  15. } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false) {
  16. $is_opera = true;
  17. } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false) {
  18. $is_NS4 = true;
  19. }
  20. $is_IE = ( $is_macIE || $is_winIE );
复制代码

php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn