Last active
March 27, 2019 08:41
-
-
Save w-jerome/8f77915ffda8a18cd36eb791c83f4cd0 to your computer and use it in GitHub Desktop.
Javascript and PHP — Detect Browser
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
var browser = (navigator.userAgent.indexOf("Chrome") > -1) ? 'chrome' : (navigator.userAgent.indexOf("Safari") > -1) ? 'safari' : (navigator.userAgent.indexOf("Opera") > -1) ? 'opera' : (navigator.userAgent.indexOf("Firefox") > -1) ? 'firefox' : (navigator.userAgent.indexOf("MSIE") > -1 || navigator.userAgent.indexOf("Trident") > -1) ? 'ie' : 'unknow'; |
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
function getBrowser() { | |
$user_agent = $_SERVER['HTTP_USER_AGENT']; | |
if (is_int(strpos($user_agent, 'Chrome'))) { | |
return 'chrome'; | |
} else if (is_int(strpos($user_agent, 'Safari'))) { | |
return 'safari'; | |
} else if (is_int(strpos($user_agent, 'Opera'))) { | |
return 'opera'; | |
} else if (is_int(strpos($user_agent, 'Firefox'))) { | |
return 'firefox'; | |
} else if (is_int(strpos($user_agent, 'MSIE')) || is_int(strpos($user_agent, 'Trident'))) { | |
return 'ie'; | |
} else { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment