PHP – Get Firefox Browser Version
The post shows you how to get the version of Firefox browser using PHP.
To do this, we simply look at User-Agent data ($_SERVER['HTTP_USER_AGENT']
) to determine whether the visitors are using Firefox browser and then extract Firefox version from it.
Here is the code:
firefox-browser.php
<?php
function getFirefoxVersion()
{
$version = null;
$userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strrpos($userAgent, 'firefox') !== false) {
preg_match('/firefox\/([0-9]+\.*[0-9]*)/', $userAgent, $matches);
if (!empty($matches)) {
$version = $matches[1];
}
}
return $version;
}
The above function returns the version if the browser is Firefox and we extract the version in the User-Agent successfully, null
if the browser is not Firefox.
Use the function:
// Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
$firefoxVersion = getFirefoxVersion();
echo $firefoxVersion;
Output:
60.0