Posted By

iTony on 10/03/08


Tagged

php browser detect


Versions (?)

Who likes this?

9 people have marked this snippet as a favorite

jamesming
JimiJay
traktorist
keame
dsntos
kucrut
vali29
nb109
userpiv


detect browser


 / Published in: PHP
 

URL: http://www.calinsoft.com/2008/10/detectando-navegadores-web-mediante-php/

  1. // Simple browser detection
  2. $is_lynx = $is_gecko = $is_winIE = $is_macIE = $is_opera = $is_NS4 = $is_safari = $is_chrome = false;
  3.  
  4. if (strpos($_SERVER['HTTP_USER_AGENT'], 'Lynx') !== false) {
  5. $is_lynx = true;
  6. } elseif ( strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'chrome') !== false ) {
  7. $is_chrome = true;
  8. } elseif ( strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'webkit') !== false ) {
  9. $is_safari = true;
  10. } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') !== false) {
  11. $is_gecko = true;
  12. } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Win') !== false) {
  13. $is_winIE = true;
  14. } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mac') !== false) {
  15. $is_macIE = true;
  16. } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== false) {
  17. $is_opera = true;
  18. } elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Nav') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla/4.') !== false) {
  19. $is_NS4 = true;
  20. }
  21.  
  22. $is_IE = ( $is_macIE || $is_winIE );

Report this snippet  

You need to login to post a comment.