Created
May 15, 2011 14:25
-
-
Save matthewpennell/973198 to your computer and use it in GitHub Desktop.
Browser sniffing with regular expressions in PHP
This file contains 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 | |
# Set browser and version environment variables based on the visitor's browser | |
preg_match_all("/(Opera|Chrome|Version|Firefox|MSIE)[\/|\s](\d+)/", $_SERVER['HTTP_USER_AGENT'], $matches, PREG_SET_ORDER); | |
list($browser, $version) = array($matches[0][1], $matches[0][2]); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment