ID: 50267 User updated by: nachumk at gmail dot com Reported By: nachumk at gmail dot com -Status: Feedback +Status: Open Bug Type: *General Issues Operating System: Windows XP 32 bit PHP Version: 5.3.1 New Comment:
Thanx for the update about browscap, I'll use that once I reinstall 5.3.1. For now I'm sticking with 5.2.11. A clearer explanation: get_browser takes 2 parameters, 'useragent' and 'as array'. useragent can be a user agent string like $customUserAgent or it can be null which should use the current user agent. The behaviour is like this, when I give it the user agent $_SERVER['HTTP_USER_AGENT'] it works fine. It detects the browser, whether it's Mozilla or iPhone or whatever. When I give it null it doesn't detect anything. It's like I gave it an empty string for user agent. I have shown the code a bit clearer by marking the lines to look at with *******. You will see that under 5.3.1 the print_r shows the returned array to be completely default when get_browser is called with a null parameter. Here's the code I'm running: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8559- 1"> </head> <body> <?php echo "User Agent: " . $_SERVER['HTTP_USER_AGENT'] . "<br>"; echo 'print_r(get_browser($_SERVER[\'HTTP_USER_AGENT\'], true));<br>'; print_r(get_browser($_SERVER['HTTP_USER_AGENT'], true)); echo '<br>print_r(get_browser(null, true))<br>'; print_r(get_browser(null, true)); ?> </html> Here's the output when 5.3.1 is installed: User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.3 (KHTML, like Gecko) Chrome/4.0.223.16 Safari/532.3 ************** Using a non-null parameter works print_r(get_browser($_SERVER['HTTP_USER_AGENT'], true)); Array ( [browser_name_regex] => §^mozilla/5\.0 \(windows; u; windows nt 5\.1; .*\) applewebkit/.* \(khtml, like gecko\) chrome/4\.0\..* safari/.*$§ [browser_name_pattern] => Mozilla/5.0 (Windows; U; Windows NT 5.1; *) AppleWebKit/* (KHTML, like Gecko) Chrome/4.0.* Safari/* [parent] => Chrome 4.0 [platform] => WinXP [browser] => Chrome [version] => 4.0 [majorver] => 4 [beta] => 1 [win32] => 1 [frames] => 1 [iframes] => 1 [tables] => 1 [cookies] => 1 [javaapplets] => 1 [javascript] => 1 [cssversion] => 3 [supportscss] => 1 [minorver] => 0 [alpha] => [win16] => [win64] => [backgroundsounds] => [cdf] => [vbscript] => [activexcontrols] => [isbanned] => [ismobiledevice] => [issyndicationreader] => [crawler] => [aol] => [aolversion] => 0 ) ****** Using a null parameter in 5.3.1 returns incorrect results: print_r(get_browser(null, true)) Array ( [browser_name_regex] => §^.*$§ [browser_name_pattern] => * [browser] => Default Browser [version] => 0 [majorver] => 0 [minorver] => 0 [platform] => unknown [alpha] => [beta] => [win16] => [win32] => [win64] => [frames] => 1 [iframes] => [tables] => 1 [cookies] => [backgroundsounds] => [cdf] => [vbscript] => [javaapplets] => [javascript] => [activexcontrols] => [isbanned] => [ismobiledevice] => [issyndicationreader] => [crawler] => [cssversion] => 0 [supportscss] => [aol] => [aolversion] => 0 ) Here's the output when 5.2.11 is installed: User Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.3 (KHTML, like Gecko) Chrome/4.0.223.16 Safari/532.3 ************** Using a non-null parameter works: print_r(get_browser($_SERVER['HTTP_USER_AGENT'], true)); Array ( [browser_name_regex] => ^mozilla/5\.0 (windows; u; windows nt 5\.1; .*) applewebkit/.* (khtml, like gecko) chrome/4\.0\..* safari/.*$ [browser_name_pattern] => Mozilla/5.0 (Windows; U; Windows NT 5.1; *) AppleWebKit/* (KHTML, like Gecko) Chrome/4.0.* Safari/* [parent] => Chrome 4.0 [platform] => WinXP [browser] => Chrome [version] => 4.0 [majorver] => 4 [beta] => 1 [win32] => 1 [frames] => 1 [iframes] => 1 [tables] => 1 [cookies] => 1 [javaapplets] => 1 [javascript] => 1 [cssversion] => 3 [supportscss] => 1 [minorver] => 0 [alpha] => [win16] => [win64] => [backgroundsounds] => [cdf] => [vbscript] => [activexcontrols] => [isbanned] => [ismobiledevice] => [issyndicationreader] => [crawler] => [aol] => [aolversion] => 0 ) *************************** 5.2.11 does this right: print_r(get_browser(null, true)) Array ( [browser_name_regex] => ^mozilla/5\.0 (windows; u; windows nt 5\.1; .*) applewebkit/.* (khtml, like gecko) chrome/4\.0\..* safari/.*$ [browser_name_pattern] => Mozilla/5.0 (Windows; U; Windows NT 5.1; *) AppleWebKit/* (KHTML, like Gecko) Chrome/4.0.* Safari/* [parent] => Chrome 4.0 [platform] => WinXP [browser] => Chrome [version] => 4.0 [majorver] => 4 [beta] => 1 [win32] => 1 [frames] => 1 [iframes] => 1 [tables] => 1 [cookies] => 1 [javaapplets] => 1 [javascript] => 1 [cssversion] => 3 [supportscss] => 1 [minorver] => 0 [alpha] => [win16] => [win64] => [backgroundsounds] => [cdf] => [vbscript] => [activexcontrols] => [isbanned] => [ismobiledevice] => [issyndicationreader] => [crawler] => [aol] => [aolversion] => 0 ) Previous Comments: ------------------------------------------------------------------------ [2009-11-23 15:44:08] [email protected] FYI: Since PHP 5.3.0 you can use the "real" browscap.ini too: http://browsers.garykeith.com/stream.asp?BrowsCapINI Can you please provide shorter and complete example script with real expected result (and actual) instead of the one you used now? I don't quite understand what the problem here is.. ------------------------------------------------------------------------ [2009-11-23 14:06:52] nachumk at gmail dot com http://browsers.garykeith.com/stream.asp?PHP_BrowsCapINI downloaded yesterday. Keep in mind that it works fine if I give it the parameter $_SERVER['HTTP_USER_AGENT'], showing that browscap is installed correctly. It seems to be an issue in php's ability to retrieve the user agent on it's own. ------------------------------------------------------------------------ [2009-11-23 10:07:01] [email protected] And what browscap.ini are you using..? ------------------------------------------------------------------------ [2009-11-23 05:20:35] nachumk at gmail dot com I am running Apache 2.2.14 (apache_2.2.14-win32-x86-openssl-0.9.8k.msi), PHP 5.3.1 (php-5.3.1-Win32-VC9-x86.msi (both as module and cgi), and php-5.3.1-nts-Win32-VC9-x86.msi), on Windows XP 32 bit. It works when I run PHP 5.2.11. ------------------------------------------------------------------------ [2009-11-23 05:18:19] nachumk at gmail dot com Description: ------------ get_browser should work with null string and doesn't when using 5.3.1. 5.2.11 works fine. Reproduce code: --------------- <?php phpinfo(); echo "User Agent: " . $_SERVER['HTTP_USER_AGENT'] . "<br>"; echo 'print_r(get_browser($_SERVER[\'HTTP_USER_AGENT\'], true));<br>'; print_r(get_browser($_SERVER['HTTP_USER_AGENT'], true)); echo '<br>print_r(get_browser(null, true))<br>'; print_r(get_browser(null, true)); ?> Expected result: ---------------- That both get_browser calls should produce identical results. Actual result: -------------- The first call with $_SERVER['HTTP_USER_AGENT'] returns proper results and the call with null returns a default response (same as what it would return with a completely empty user agent string). ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50267&edit=1
