Created
July 24, 2014 15:39
-
-
Save Fonger/6ac0ba31e19115f6fbc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$browsers = array('firefox','chrome','safari','opera','msie'); | |
$browser = new stdClass(); | |
preg_match('#('.implode('|',$browsers).')(/| )([^ ]+)#i',$_SERVER['HTTP_USER_AGENT'],$match); | |
$browser->version = round((int)$match[3]); | |
$match = strtolower($match[1]); | |
foreach($browsers as $val) | |
{ | |
$browser->{$val} = ($match == $val ? TRUE : FALSE); | |
} | |
if($browser->safari || $browser->opera) | |
{ | |
preg_match('#version/([^ ]+)#i',$_SERVER['HTTP_USER_AGENT'],$match); | |
$browser->version = round((int)$match[1]); | |
} | |
$browser->webkit = ($browser->chrome || $browser->safari ? TRUE : FALSE); | |
var_dump($browser); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment