Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/UserAgent/Browsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Browsers {
const BROWSER = 'Browser';
const BUNJALLOO = 'Bunjalloo';
const CAMINO = 'Camino';
const CHATGPT_USER = 'ChatGPT-User';
const CHROME = 'Chrome';
const CURL = 'curl';
const EDGE = 'Edge';
Expand All @@ -24,6 +25,7 @@ interface Browsers {
const GOOGLEBOT = 'Googlebot';
const GOOGLEBOT_IMAGE = 'Googlebot-Image';
const GOOGLEBOT_VIDEO = 'Googlebot-Video';
const GPTBOT = 'GPTBot';
const HEADLESSCHROME = 'HeadlessChrome';
const IEMOBILE = 'IEMobile';
const IMESSAGEBOT = 'iMessageBot';
Expand All @@ -35,6 +37,7 @@ interface Browsers {
const MSNBOT_MEDIA = 'msnbot-media';
const NETFRONT = 'NetFront';
const NINTENDOBROWSER = 'NintendoBrowser';
const OAI_SEARCHBOT = 'OAI-SearchBot';
const OCULUSBROWSER = 'OculusBrowser';
const OPERA = 'Opera';
const PUFFIN = 'Puffin';
Expand Down
26 changes: 16 additions & 10 deletions src/UserAgentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function parse_user_agent( $u_agent = null ) {
} elseif( $platform == 'Adr' ) {
$platform = 'Android';
} elseif( $platform === null ) {
if(preg_match_all('%(?P<platform>Android)[:/ ]%ix', $u_agent, $result)) {
if( preg_match_all('%(?P<platform>Android)[:/ ]%ix', $u_agent, $result) ) {
$platform = $result[PLATFORM][0];
}
}
Expand All @@ -99,11 +99,12 @@ function parse_user_agent( $u_agent = null ) {
%(?P<browser>Camino|Kindle(\ Fire)?|Firefox|Iceweasel|IceCat|Safari|MSIE|Trident|AppleWebKit|
TizenBrowser|(?:Headless)?Chrome|YaBrowser|Vivaldi|IEMobile|Opera|OPR|Silk|Midori|(?-i:Edge)|EdgA?|CriOS|UCBrowser|Puffin|
OculusBrowser|SamsungBrowser|SailfishBrowser|XiaoMi/MiuiBrowser|YaApp_Android|
Baiduspider|Applebot|Facebot|Googlebot|YandexBot|bingbot|Lynx|Version|Wget|curl|
Baiduspider|Applebot|Facebot|Googlebot|YandexBot|bingbot|Lynx|Version|Wget|curl|ChatGPT-User|GPTBot|OAI-SearchBot|
Valve\ Steam\ Tenfoot|
NintendoBrowser|PLAYSTATION\ (?:\d|Vita)+)
\)?;?
(?:[:/ ](?P<version>[0-9A-Z.]+)|/[A-Z]*)%ix
(?:[:/ ](?P<version>[0-9A-Z.]+)|/[A-Z]*)
%ix
REGEX
, $u_agent, $result);

Expand All @@ -125,7 +126,7 @@ function parse_user_agent( $u_agent = null ) {

$lowerBrowser = array_map('strtolower', $result[BROWSER]);

$find = function ( $search, &$key = null, &$value = null ) use ( $lowerBrowser ) {
$find = function( $search, &$key = null, &$value = null ) use ( $lowerBrowser ) {
$search = (array)$search;

foreach( $search as $val ) {
Expand All @@ -141,7 +142,7 @@ function parse_user_agent( $u_agent = null ) {
return false;
};

$findT = function ( array $search, &$key = null, &$value = null ) use ( $find ) {
$findT = function( array $search, &$key = null, &$value = null ) use ( $find ) {
$value2 = null;
if( $find(array_keys($search), $key, $value2) ) {
$value = $search[$value2];
Expand All @@ -168,7 +169,7 @@ function parse_user_agent( $u_agent = null ) {
} elseif( $find('NintendoBrowser', $key) || $platform == 'Nintendo 3DS' ) {
$browser = 'NintendoBrowser';
$version = $result[BROWSER_VERSION][$key];
} elseif( $find('Kindle', $key, $platform) ) {
} elseif( $find([ 'Kindle' ], $key, $platform) ) {
$browser = $result[BROWSER][$key];
$version = $result[BROWSER_VERSION][$key];
} elseif( $find('Opera', $key, $browser) ) {
Expand Down Expand Up @@ -200,12 +201,17 @@ function parse_user_agent( $u_agent = null ) {
$platform = 'BlackBerry';
} elseif( $platform == 'BlackBerry' || $platform == 'PlayBook' ) {
$browser = 'BlackBerry Browser';
} else {
$find('Safari', $key, $browser) || $find('TizenBrowser', $key, $browser);
} elseif( $find('Safari', $key, $browser) || $find('TizenBrowser', $key, $browser) ) {
$version = $result[BROWSER_VERSION][$key];
} elseif( count($result[BROWSER]) ) {
$key = count($result[BROWSER]) - 1;
$browser = $result[BROWSER][$key];
$version = $result[BROWSER_VERSION][$key];
}

$find('Version', $key);
$version = $result[BROWSER_VERSION][$key];
if( $find('Version', $key) ) {
$version = $result[BROWSER_VERSION][$key];
}
} elseif( $pKey = preg_grep('/playstation \d/i', $result[BROWSER]) ) {
$pKey = reset($pKey);

Expand Down
15 changes: 15 additions & 0 deletions tests/user_agents.dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,11 @@
"browser": "bingbot",
"version": "2.0"
},
"Mozilla\/5.0 AppleWebKit\/537.36 (KHTML, like Gecko); compatible; ChatGPT-User\/1.0; +https:\/\/openai.com\/bot": {
"platform": null,
"browser": "ChatGPT-User",
"version": "1.0"
},
"curl\/7.19.7 (universal-apple-darwin10.0) libcurl\/7.19.7 OpenSSL\/0.9.8r zlib\/1.2.3": {
"platform": null,
"browser": "curl",
Expand Down Expand Up @@ -1439,6 +1444,11 @@
"browser": "Googlebot-Video",
"version": "1.0"
},
"Mozilla\/5.0 AppleWebKit\/537.36 (KHTML, like Gecko); compatible; GPTBot\/1.1; +https:\/\/openai.com\/gptbot": {
"platform": null,
"browser": "GPTBot",
"version": "1.1"
},
"Lynx\/2.8.6rel.4 libwww-FM\/2.14 SSL-MM\/1.4.1 OpenSSL\/0.9.7l Lynxlet\/0.7.0": {
"platform": null,
"browser": "Lynx",
Expand All @@ -1449,6 +1459,11 @@
"browser": "msnbot-media",
"version": "1.1"
},
"Mozilla\/5.0 AppleWebKit\/537.36 (KHTML, like Gecko); compatible; OAI-SearchBot\/1.0; +https:\/\/openai.com\/searchbot": {
"platform": null,
"browser": "OAI-SearchBot",
"version": "1.0"
},
"Slackbot 1.0 (+https:\/\/api.slack.com\/robots)": {
"platform": null,
"browser": "Slackbot",
Expand Down