
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
parse-user-agent
Advanced tools
parseUserAgent is a function that takes a user agent and returns the browser name and version (and soon the operating system and version).
parseUserAgent is a function that takes a user agent and returns the name and version of the corresponding browser & operating system.
There are many libraries and solutions for this problem, but I decided to re-invent the wheel and write my own as I've not found one that did all of the following:
<?php
$user_agent = $_SERVER['HTTP_USER_AGENT'];
// Mozilla/5.0 (Linux; Android 10; BLA-L09) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.96 Mobile Safari/537.36 (Ecosia android@78.0.3904.96)
print_r(
parseUserAgent($user_agent)
);
The above code will output:
Array
(
[browser_name] => Ecosia Browser
[browser_version] => android@78.0.3904.96
[operating_system_name] => Android
[operating_system_version] => 10
[is_mobile] => 1
)
let user_agent = request.headers["user-agent"];
// Mozilla/5.0 (Linux; Android 10; BLA-L09) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.96 Mobile Safari/537.36 (Ecosia android@78.0.3904.96)
console.table(parseUserAgent(user_agent));
The above code will output:
āāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāā
ā (index) ā Values ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāā¤
ā browser_name ā 'Ecosia Browser' ā
ā browser_version ā 'android@78.0.3904.96' ā
ā operating_system_name ā 'Android' ā
ā operating_system_version ā '10' ā
ā is_mobile ā true ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāāāāāāāāāāāāāāā
Included in both PHP and JavaScript versions, is a function to convert Windows versions to public names:
let user_agent = request.headers["user-agent"];
// Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)
let user_agent_parsed = parseUserAgent(user_agent);
console.table(user_agent_parsed);
user_agent_parsed = parseWindowsVersion(user_agent_parsed);
console.table(user_agent_parsed);
The above code will output:
āāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāā
ā (index) ā Values ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāā¤
ā browser_name ā 'Arora' ā
ā browser_version ā '0.3' ā
ā operating_system_name ā 'Windows' ā
ā operating_system_version ā '5.1' ā
ā is_mobile ā false ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāā
ā (index) ā Values ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāā¤
ā browser_name ā 'Arora' ā
ā browser_version ā '0.3' ā
ā operating_system_name ā 'Windows' ā
ā operating_system_version ā 'XP' ā
ā is_mobile ā false ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāā“āāāāāāāāāāāā
Function accepts either a JavaScript object/PHP array with "operating_system_version" key, or just a string:
console.log(parseWindowsVersion("5.1")); // XP
FAQs
parseUserAgent is a function that takes a user agent and returns the browser name and version (and soon the operating system and version).
The npm package parse-user-agent receives a total of 9 weekly downloads. As such, parse-user-agent popularity was classified as not popular.
We found that parse-user-agent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.Ā It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.