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>
<html>
<head>
<script>
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(){
alert(detectBrowser());
}
</script>
</head>
<body>
</br>
</br></br>
<button onclick="browserCheck();">Click here to check!</button>
</body>
</html>

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;

OR
You can also try this code

function GetBrowserName()
{

$GetBrowserNameUA=$_SERVER[‘HTTP_USER_AGENT’];

If (strpos(strtolower($GetBrowserNameUA), “safari/”) and strpos(strtolower($GetBrowserNameUA), “opr/”)) {
// OPERA
$GetBrowserNameBR=”Opera”;
} ElseIf (strpos(strtolower($GetBrowserNameUA), “safari/”) and strpos(strtolower($GetBrowserNameUA), “chrome/”)) {
// CHROME
$GetBrowserNameBR=”Chrome”;
} ElseIf (strpos(strtolower($GetBrowserNameUA), “msie”)) {
// INTERNET EXPLORER
$GetBrowserNameBR=”Internet Explorer”;
} ElseIf (strpos(strtolower($GetBrowserNameUA), “firefox/”)) {
// FIREFOX
$GetBrowserNameBR=”Firefox”;
} ElseIf (strpos(strtolower($GetBrowserNameUA), “safari/”) and strpos(strtolower($GetBrowserNameUA), “opr/”)==false and strpos(strtolower($GetBrowserNameUA), “chrome/”)==false) {
// SAFARI
$GetBrowserNameBR=”Safari”;
} Else {
// OUT OF DATA
$GetBrowserNameBR=”OUT OF DATA”;
};

return $GetBrowserNameBR;
}

echo GetBrowserName();

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts: You may like

How to login with LinkedIn oAuth2 in PHP

Extract Total Number of Image And Missing Alt Attribute using php

How to extract Heading tags using PHP from string

How To Create a Modal Popup With CSS and JavaScript

How to remove whitespace from string using php

Remove All Special Characters From String PHP

Get Latitude Longitude from Address

Redirecting HTTP to HTTPS with PHP

cookie policy popup

Convert Base64 string to an image file

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Free online tool to download Instagram videos, photos and save Instagram videos, photos to your device. It's free & easy to use.

Download Now

CURRENCY CONVERTER

Our real time currency converter calculator will convert your money based on current values from around the world. It's free & easy to use.

Convert Now

ROBOST.TXT GEN.

Create robots txt file that help search engines to crawling and indexing your site with help of our free online Robots.txt Generator tool.

Create Now

HTML MINIFIER

Free online tool to minify or compress html code and reduce the size of html code in few clicks. It's free & easy to use.

Minify Now

CSS MINIFIER

Free online tool to minify or compress css code and reduce the size of css code in few clicks. It's free & easy to use.

Minify Now

JAVASCRIPT MINIFIER

Free online tool to minify or compress javascript code and reduce the size of javascript code in few clicks. It's free & easy to use.

Minify Now

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.