Skip to content

Commit b180517

Browse files
committed
Fix issue when running from CLI
1 parent b938ea4 commit b180517

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/phpUserAgentStringParser.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class phpUserAgentStringParser
1818
*/
1919
public function parse($userAgentString = null)
2020
{
21-
// use current user agetn string as default
21+
// use current user agent string as default
2222
if(!$userAgentString)
2323
{
24-
$userAgentString = $_SERVER['HTTP_USER_AGENT'];
24+
$userAgentString = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
2525
}
2626

2727
// parse quickly (with medium accuracy)
@@ -51,6 +51,11 @@ protected function doParse($userAgentString)
5151
'operating_system' => null
5252
);
5353

54+
if(empty($userAgent['string']))
55+
{
56+
return $userAgent;
57+
}
58+
5459
// build regex that matches phrases for known browsers
5560
// (e.g. "Firefox/2.0" or "MSIE 6.0" (This only matches the major and minor
5661
// version numbers. E.g. "2.0.0.6" is parsed as simply "2.0"

0 commit comments

Comments
 (0)