how to get exact browser name and version

Get browser name and version using javascript

With the help of JavaScript we can determine exact browser name and its version. The JavaScript object “navigator.userAgent” contains the complete information of a browser like CodeName, Name, Version etc. With the help of regular expressions we can extract the information that we need.

<!DOCTYPE html>
function detectBrowser(){
var N= navigator.appName;
var UA= navigator.userAgent;
var temp;
var browserVersion= UA.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
if(browserVersion && (temp= UA.match(/version\/([\.\d]+)/i))!= null)
browserVersion[2]= temp[1];
browserVersion= browserVersion? [browserVersion[1], browserVersion[2]]: [N, navigator.appVersion,'-?'];
return browserVersion;
function browserCheck(){
<button onclick="browserCheck();">Click here to check!</button>

Get browser name and version using PHP

Here we are determine exact browser name and its version with the help of PHP.

$browserAgent = $_SERVER['HTTP_USER_AGENT'];
echo $browserAgent;

You can also try this code

function GetBrowserName()


If (strpos(strtolower($GetBrowserNameUA), “safari/”) and strpos(strtolower($GetBrowserNameUA), “opr/”)) {
} ElseIf (strpos(strtolower($GetBrowserNameUA), “safari/”) and strpos(strtolower($GetBrowserNameUA), “chrome/”)) {
} ElseIf (strpos(strtolower($GetBrowserNameUA), “msie”)) {
$GetBrowserNameBR=”Internet Explorer”;
} ElseIf (strpos(strtolower($GetBrowserNameUA), “firefox/”)) {
} ElseIf (strpos(strtolower($GetBrowserNameUA), “safari/”) and strpos(strtolower($GetBrowserNameUA), “opr/”)==false and strpos(strtolower($GetBrowserNameUA), “chrome/”)==false) {
} Else {
$GetBrowserNameBR=”OUT OF DATA”;

return $GetBrowserNameBR;

echo GetBrowserName();

About Author

My name is Mukesh Jakhar and I am a Web Application Developer and Software Developer, currently living in Jaipur, India. I have a Master of Computer Application in Computer Science from JNU Jaipur University. I loves to write on technology and programming topics. Apart from this, I love to travel and enjoy the beauty of nature.

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.