Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Quoting <a href="http://apptools.com/phptools/browser/" rel="nofollow">this</a> blog :</p> <blockquote> <p>Browser detection is an illusive task that is ultimately doomed to fail. Browsers are always changing and keeping up to date with these changes is a continuous job. Some browsers allow the user to alter the way the browser identifies itself, or to not identify itself at all. Some firewalls block the sending of the browser identification, so no browser detection scheme is entirely successful.</p> </blockquote> <p><strong>NOTE :</strong> also, read more about browser detection bad practice <a href="https://developer.mozilla.org/en/browser_detection_and_cross_browser_support" rel="nofollow">here</a>.</p> <p>However, that being said here's <a href="http://www.phpclasses.org/browse/file/12369.html" rel="nofollow">a script</a> I once used :</p> <pre><code>&lt;?php /** * Class to detect which browser is currently accessing the page/site * @author Paul Scott * This class is very loosely based on scripts by Gary White * @copyright Paul Scott * @package browser */ class browser { /** * @var string $name */ var $name = NULL; /** * @var string $version */ var $version = NULL; /** * @var $useragent */ var $useragent = NULL; /** * @var string $platform */ var $platform; /** * @var string aol */ var $aol = FALSE; /** * @var string browser */ var $browsertype; /** * Class constructor * @param void * @return void */ function browser() { $agent = $_SERVER['HTTP_USER_AGENT']; //set the useragent property $this-&gt;useragent = $agent; } /** * Method to get the browser details from the USER_AGENT string in * the PHP superglobals * @param void * @return string property platform */ function getBrowserOS() { $win = eregi("win", $this-&gt;useragent); $linux = eregi("linux", $this-&gt;useragent); $mac = eregi("mac", $this-&gt;useragent); $os2 = eregi("OS/2", $this-&gt;useragent); $beos = eregi("BeOS", $this-&gt;useragent); //now do the check as to which matches and return it if($win) { $this-&gt;platform = "Windows"; } elseif ($linux) { $this-&gt;platform = "Linux"; } elseif ($mac) { $this-&gt;platform = "Macintosh"; } elseif ($os2) { $this-&gt;platform = "OS/2"; } elseif ($beos) { $this-&gt;platform = "BeOS"; } return $this-&gt;platform; } /** * Method to test for Opera * @param void * @return property $broswer * @return property version * @return bool false on failure */ function isOpera() { // test for Opera if (eregi("opera",$this-&gt;useragent)) { $val = stristr($this-&gt;useragent, "opera"); if (eregi("/", $val)){ $val = explode("/",$val); $this-&gt;browsertype = $val[0]; $val = explode(" ",$val[1]); $this-&gt;version = $val[0]; }else{ $val = explode(" ",stristr($val,"opera")); $this-&gt;browsertype = $val[0]; $this-&gt;version = $val[1]; } return TRUE; } else { return FALSE; } } /** * Method to check for FireFox * @param void * @return bool false on failure */ function isFirefox() { if(eregi("Firefox", $this-&gt;useragent)) { $this-&gt;browsertype = "Firefox"; $val = stristr($this-&gt;useragent, "Firefox"); $val = explode("/",$val); $this-&gt;version = $val[1]; return true; } else { return FALSE; } } /** * Method to check for Konquerer * @param void * @return prop $browser * @return prop $version * @return bool true on success */ function isKonqueror() { if(eregi("Konqueror",$this-&gt;useragent)) { $val = explode(" ",stristr($this-&gt;useragent,"Konqueror")); $val = explode("/",$val[0]); $this-&gt;browsertype = $val[0]; $this-&gt;version = str_replace(")","",$val[1]); return TRUE; } else { return FALSE; } }//end func /** * Method to check for Internet Explorer v1 * @param void * @return bool true on success * @return prop $browsertype * @return prop $version */ function isIEv1() { if(eregi("microsoft internet explorer", $this-&gt;useragent)) { $this-&gt;browsertype = "MSIE"; $this-&gt;version = "1.0"; $var = stristr($this-&gt;useragent, "/"); if (ereg("308|425|426|474|0b1", $var)) { $this-&gt;version = "1.5"; } return TRUE; } else { return FALSE; } }//end function /** * Method to check for Internet Explorer later than v1 * @param void * @return bool true on success * @return prop $browsertype * @return prop $version */ function isMSIE() { if(eregi("msie", $this-&gt;useragent) &amp;&amp; !eregi("opera",$this-&gt;useragent)) { $this-&gt;browsertype = "MSIE"; $val = explode(" ",stristr($this-&gt;useragent,"msie")); $this-&gt;browsertype = $val[0]; $this-&gt;version = $val[1]; return TRUE; } else { return FALSE; } }//end function /** * Method to check for Galeon * @param void * @return bool true on success */ function isGaleon() { if(eregi("galeon",$this-&gt;useragent)) { $val = explode(" ",stristr($this-&gt;useragent,"galeon")); $val = explode("/",$val[0]); $this-&gt;browsertype = $val[0]; $this-&gt;version = $val[1]; return TRUE; } else { return FALSE; } }//end func /** * Now we do the tests for browsers I can't test... * If someone finds a bug, please report it ASAP to me please! */ /** * Method to check for WebTV browser * @param void * @return bool true on success * @return prop $browsertype * @return prop $version */ function isWebTV() { if(eregi("webtv",$this-&gt;useragent)) { $val = explode("/",stristr($this-&gt;useragent,"webtv")); $this-&gt;browsertype = $val[0]; $this-&gt;version = $val[1]; return TRUE; } else { return FALSE; } } /** * Method to check for BeOS's NetPositive * @param void * @return bool true on success * @return prop $browsertype * @return prop $version */ function isNetPositive() { if(eregi("NetPositive", $this-&gt;useragent)) { $val = explode("/",stristr($this-&gt;useragent,"NetPositive")); $this-&gt;platform = "BeOS"; $this-&gt;browsertype = $val[0]; $this-&gt;version = $val[1]; return TRUE; } else { return FALSE; } } /** * Method to check for MSPIE (Pocket IE) * @param void * @return bool true on success */ function isMSPIE() { if(eregi("mspie",$this-&gt;useragent) || eregi("pocket", $this-&gt;useragent)) { $val = explode(" ",stristr($this-&gt;useragent,"mspie")); $this-&gt;browsertype = "MSPIE"; $this-&gt;platform = "WindowsCE"; if (eregi("mspie", $this-&gt;useragent)) $this-&gt;version = $val[1]; else { $val = explode("/",$this-&gt;useragent); $this-&gt;version = $val[1]; } return TRUE; } else { return FALSE; } } /** * Method to test for iCab * @param void * @return bool true on success */ function isIcab() { if(eregi("icab",$this-&gt;useragent)) { $val = explode(" ",stristr($this-&gt;useragent,"icab")); $this-&gt;browsertype = $val[0]; $this-&gt;version = $val[1]; return TRUE; } else { return FALSE; } } /** * Method to test for the OmniWeb Browser * @param void * @return bool True on success */ function isOmniWeb() { if(eregi("omniweb",$this-&gt;useragent)) { $val = explode("/",stristr($this-&gt;useragent,"omniweb")); $this-&gt;browsertype = $val[0]; $this-&gt;version = $val[1]; return TRUE; } else { return FALSE; } } /** * Method to check for Phoenix Browser * @param void * @return bool true on success */ function isPhoenix() { if(eregi("Phoenix", $this-&gt;useragent)) { $this-&gt;browsertype = "Phoenix"; $val = explode("/", stristr($this-&gt;useragent,"Phoenix/")); $this-&gt;version = $val[1]; return TRUE; } else { return FALSE; } } /** * Method to check for Firebird * @param void * @return bool true on success */ function isFirebird() { if(eregi("firebird", $this-&gt;useragent)) { $this-&gt;browsertype = "Firebird"; $val = stristr($this-&gt;useragent, "Firebird"); $val = explode("/",$val); $this-&gt;version = $val[1]; return TRUE; } else { return FALSE; } } /** * Method to check for Mozilla alpha/beta * @param void * @return bool true on success */ function isMozAlphaBeta() { if(eregi("mozilla",$this-&gt;useragent) &amp;&amp; eregi("rv:[0-9].[0-9][a-b]",$this-&gt;useragent) &amp;&amp; !eregi("netscape",$this-&gt;useragent)) { $this-&gt;browsertype = "Mozilla"; $val = explode(" ",stristr($this-&gt;useragent,"rv:")); eregi("rv:[0-9].[0-9][a-b]",$this-&gt;useragent,$val); $this-&gt;version = str_replace("rv:","",$val[0]); return TRUE; } else { return FALSE; } }//end function /** * Method to check for Mozilla Stable versions * @param void * @return bool true on success */ function isMozStable() { if(eregi("mozilla",$this-&gt;useragent) &amp;&amp; eregi("rv:[0-9]\.[0-9]",$this-&gt;useragent) &amp;&amp; !eregi("netscape",$this-&gt;useragent)) { $this-&gt;browsertype = "Mozilla"; $val = explode(" ",stristr($this-&gt;useragent,"rv:")); eregi("rv:[0-9]\.[0-9]\.[0-9]",$this-&gt;useragent,$val); $this-&gt;version = str_replace("rv:","",$val[0]); return TRUE; } else { return FALSE; } } /** * Method to check for Lynx and Amaya * @param void * @return bool true on success */ function isLynx() { if(eregi("libwww", $this-&gt;useragent)) { if (eregi("amaya", $this-&gt;useragent)) { $val = explode("/",stristr($this-&gt;useragent,"amaya")); $this-&gt;browsertype = "Amaya"; $val = explode(" ", $val[1]); $this-&gt;version = $val[0]; } else { $val = explode("/",$this-&gt;useragent); $this-&gt;browsertype = "Lynx"; $this-&gt;version = $val[1]; } return TRUE; } else { return FALSE; } } /** * method to check for safari browser * @param void * @return bool true on success */ function isSafari() { if(eregi("safari", $this-&gt;useragent)) { $this-&gt;browsertype = "Safari"; $this-&gt;version = ""; return TRUE; } else { return FALSE; } } /** * Various tests for Netscrape * @param void * @return bool true on success */ function isNetscape() { if(eregi("netscape",$this-&gt;useragent)) { $val = explode(" ",stristr($this-&gt;useragent,"netscape")); $val = explode("/",$val[0]); $this-&gt;browsertype = $val[0]; $this-&gt;version = $val[1]; return TRUE; } elseif(eregi("mozilla",$this-&gt;useragent) &amp;&amp; !eregi("rv:[0-9]\.[0-9]\.[0-9]",$this-&gt;useragent)) { $val = explode(" ",stristr($this-&gt;useragent,"mozilla")); $val = explode("/",$val[0]); $this-&gt;browsertype = "Netscape"; $this-&gt;version = $val[1]; return TRUE; } else { return FALSE; } }//end func /** * Method to check for AOL connections * @param void * @return bool true on Success */ function isAOL() { if (eregi("AOL", $this-&gt;useragent)){ $var = stristr($this-&gt;useragent, "AOL"); $var = explode(" ", $var); $this-&gt;aol = ereg_replace("[^0-9,.,a-z,A-Z]", "", $var[1]); return TRUE; } else { return FALSE; } } /** * Method to tie them all up and output something useful * @param void * @return array */ function whatBrowser() { $this-&gt;getBrowserOS(); $this-&gt;isOpera(); $this-&gt;isFirefox(); $this-&gt;isKonqueror(); $this-&gt;isIEv1(); $this-&gt;isMSIE(); $this-&gt;isGaleon(); $this-&gt;isNetPositive(); $this-&gt;isMSPIE(); $this-&gt;isIcab(); $this-&gt;isOmniWeb(); $this-&gt;isPhoenix(); $this-&gt;isFirebird(); $this-&gt;isLynx(); $this-&gt;isSafari(); //$this-&gt;isMozAlphaBeta(); //$this-&gt;isMozStable(); //$this-&gt;isNetscape(); $this-&gt;isAOL(); return array('browsertype' =&gt; $this-&gt;browsertype, 'version' =&gt; $this-&gt;version, 'platform' =&gt; $this-&gt;platform, 'AOL' =&gt; $this-&gt;aol); } }//end class ?&gt; </code></pre> <p>As per mentioned, <a href="http://www.quirksmode.org/css/condcom.html" rel="nofollow">conditional comments</a> may only work with IE, however you'll solve about 90% of the problems right there.</p> <p>On another note, you may find <a href="http://framework.zend.com/code/filedetails.php?repname=Zend+Framework&amp;path=/trunk/library/Zend/Locale.php" rel="nofollow">Zend_Locale</a> interesting to return browser language, etc.</p> <p>In any case, you'll be better off targeting which browser you wish to support the most, focus on that one and try to be compliant with other browsers in the end. (It's always a good idea to "Target the standards and not particular browsers", though.) It's a damn task that we all have to go through (unless one use frameworks such as Echo2, GWT, etc.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload