ID: 50267
Updated by: jani@php.net
Reported By: nachumk at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: *General Issues
Operating System: Windows XP 32 bit
PHP Version: 5.3.1
New Comment:
It's quite simple: what does $_SERVER['HTTP_USER_AGENT'] contain when
you get the wrong result? Try var_dump() it? And then copy'paste to a
script. For example script look at: http://php.net/get_browser
Previous Comments:
------------------------------------------------------------------------
[2009-11-23 22:11:53] nachumk at gmail dot com
I do not know how I would create a standalone script that would have a
default user agent... Why would I even want to do that?? The problem
is from within a browser running the get_browser function... Sort of,
server side of course.
I don't know how I would set the PHP variables for a browser in a
script. Please read my posts, I think they're extremely clear. If you
would like more information from me then please, and by all means,
ask.
Re: Hint: It can NOT contain this: $_SERVER['HTTP_USER_AGENT']:
What??? The get_browser function should on its own use this variable
value. I am showing by inputting it manually that get_browser isn't
working properly!
Thank you, and please forgive me if I'm acting like a newbie. Perhaps
there is something I don't know and if you could explain to me what
that is I would be obliged.
------------------------------------------------------------------------
[2009-11-23 18:41:06] jani@php.net
I'll try again, but I'm running out of wire: Provide a standalone
script that can be run on command line to reproduce the issue in simple
manner. Hint: It can NOT contain this: $_SERVER['HTTP_USER_AGENT'].
------------------------------------------------------------------------
[2009-11-23 16:17:13] nachumk at gmail dot com
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 )
------------------------------------------------------------------------
[2009-11-23 15:44:08] jani@php.net
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.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/50267
--
Edit this bug report at http://bugs.php.net/?id=50267&edit=1