PHP Code Detect Browser - Php

How to detect browser using php code?

Snippet Code


  
Rate this page :
  [ 0 votes]

You can easily detect which browser is using for your web pages. Here, the function get_browser_name() is used to identify the browser.

<?php function get_browser_name(){ $useragent = $_SERVER['HTTP_USER_AGENT']; $browser = "Unknown Browser"; if (preg_match('/msie/i', $useragent) amp&!preg_match('/opera/i', $useragent)) { $browser = "Internet Explorer"; } else if (preg_match('/firefox/i', $useragent)) { $browser = "Firefox"; } else if (preg_match('/chrome/i', $useragent)) { $browser = "Chrome"; } else if (preg_match('/safari/i', $useragent)) { $browser = "Safari"; } else if (preg_match('/opera/i', $useragent)) { $browser = "Opera"; } else if (preg_match('/netscape/i', $useragent)) { $browser = "Netscape"; } return $browser; } echo get_browser_name(); ?>

Tags


Ask Questions

Ask Question