php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69983 get_browser fails with user agent of null
Submitted: 2015-07-02 21:11 UTC Modified: 2015-07-03 23:59 UTC
From: php7testing at prodpartners dot com Assigned: Kalle (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 7.0.0alpha2 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php7testing at prodpartners dot com
New email:
PHP Version: OS:

 

 [2015-07-02 21:11 UTC] php7testing at prodpartners dot com
Description:
------------
get browser issues a warning on 7.0 alpha 2 when user-agent string is null - works fine on 5.6.8.

get_browser works with user-agent string of $_SERVER['HTTP_USER_AGENT']

Warning: get_browser(): HTTP_USER_AGENT variable is not set, cannot determine user agent name in /usr/local/apache2/htdocs/php7testing/browscap_test.php on line 2


Test script:
---------------
<?php
	$browser=get_browser(NULL, true);
	print_r($browser);
?>


Patches

bug69983.phpt (last revision 2015-07-03 18:42 UTC by cmb@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-03 02:59 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2015-07-03 02:59 UTC] laruence@php.net
$ /home/huixinchen/local/php56/bin/php -dbrowscap=/tmp/browscap.ini /tmp/1.php

Warning: get_browser(): HTTP_USER_AGENT variable is not set, cannot determine user agent name in /tmp/1.php on line 2

I get same warning in 5.6, did I misunderstand you?
 [2015-07-03 11:46 UTC] php7testing at prodpartners dot com
-Status: Feedback +Status: Open
 [2015-07-03 11:46 UTC] php7testing at prodpartners dot com
Using the code snippet in this report:

With 5.6.8 I do not get a warning and I get the following output from print_r:

Array ( [browser_name_regex] => ~^mozilla/5\.0 \(.*windows nt 6\.1.*\) gecko.* firefox/38\.0.*$~ [browser_name_pattern] => Mozilla/5.0 (*Windows NT 6.1*) Gecko* Firefox/38.0* [parent] => Firefox 38.0 [platform] => Win7 [comment] => Firefox 38.0 [browser] => Firefox [version] => 38.0 [device_type] => Desktop [ismobiledevice] => [istablet] => ) 

With 7.0 Alpha 2 I get the warning listed in this bug report and I do not get any output from print_r.

The tests are run on the same machine.  To change versions I stop php-fpm, run make install for the version that I want, and then start php-fpm.
 [2015-07-03 14:17 UTC] laruence@php.net
you can check $_SERVER["HTTP_USER_AGENT"] by dumping it before calling get_browse, this probably relates to some issue of your configuration in nginx fastcgi params
 [2015-07-03 14:19 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2015-07-03 14:19 UTC] laruence@php.net
you can check $_SERVER["HTTP_USER_AGENT"] by dumping it before calling get_browse, this probably relates to some issue of your configuration in nginx fastcgi params
 [2015-07-03 16:17 UTC] php7testing at prodpartners dot com
-Status: Feedback +Status: Open
 [2015-07-03 16:17 UTC] php7testing at prodpartners dot com
Perhaps I did not make it clear.  The problem only exists when you use a value of NULL for the user agent parameter.  It works when I provide $_SERVER["HTTP_USER_AGENT"] for that parameter. 

I don't think that the problem has anything to do with the fastcgi configuration because of two reasons:
1) I am using Apache 2.4 and php-fpm not nginx
2) It works with the same configuration on the same machine under 5.6.8

The following is the output when I first echo $_SERVER["HTTP_USER_AGENT"] and then call get_browser(NULL, true).  I included 2 "<br>" after echoing $_SERVER["HTTP_USER_AGENT"] to delineate that output from that of get_browser.

Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0

Warning: get_browser(): HTTP_USER_AGENT variable is not set, cannot determine user agent name in /usr/local/apache2/htdocs/php7testing/browscap_test.php on line 3

The main reason that I am bringing this up is that PHP 7 behavior is different from 5.6 and from the documentation.  I am trying to help eliminate problems for others making the transition from 5.X to 7.
 [2015-07-03 16:41 UTC] cmb@php.net
-Summary: get_browser fails on 7.0 with user agent of null works on 5.6.8 +Summary: get_browser fails on 7.0 with user agent of null works on 5.6.10 -Status: Open +Status: Verified -Package: *General Issues +Package: Unknown/Other Function -Operating System: Centos 7 +Operating System: * -Assigned To: +Assigned To: cmb
 [2015-07-03 16:41 UTC] cmb@php.net
I can confirm this issue for PHP 7.0.0-alpha2 with the CLI server
on Windows. Works fine with PHP 5.6.10, though. I'll do some
debugging.
 [2015-07-03 17:29 UTC] cmb@php.net
-Assigned To: cmb +Assigned To: laruence
 [2015-07-03 17:29 UTC] cmb@php.net
There seems to be a logic error in the detection of the user
agent[1]. zend_is_auto_global_str(ZEND_STRL("_SERVER"))) yields 1,
and so the error is triggered.

Is it supposed to be
!zend_is_auto_global_str(ZEND_STRL("_SERVER")))?

@laruence: Can you please have a look at the issue?

[1] <http://lxr.php.net/xref/PHP_TRUNK/ext/standard/browscap.c#465>
 [2015-07-03 18:42 UTC] cmb@php.net
The following patch has been added/updated:

Patch Name: bug69983.phpt
Revision:   1435948945
URL:        https://bugs.php.net/patch-display.php?bug=69983&patch=bug69983.phpt&revision=1435948945
 [2015-07-03 22:50 UTC] kalle@php.net
-Assigned To: laruence +Assigned To: cmb
 [2015-07-03 22:50 UTC] kalle@php.net
Christoph, I think its the conditional that is wrong, instead of || after the zend_is_auto_global() call, use &&, like other places where the same code is used seems right, but so far I cannot properly test since I only got CLI available.

(Assigned it to you, to notice this comment)
 [2015-07-03 23:59 UTC] cmb@php.net
-Summary: get_browser fails on 7.0 with user agent of null works on 5.6.10 +Summary: get_browser fails with user agent of null -Assigned To: cmb +Assigned To: Kalle
 [2015-07-03 23:59 UTC] cmb@php.net
Thanks for having a look, Kalle. Frankly, I can't tell, what's the
correct solution. This goes too deep into the innards of the
engine, and is well beyond my (current) comprehension. The
relevant commit is da7d94c[1], and indeed that suggests that the
|| should be a &&, and with this change the test script also
succeeds.

> I cannot properly test since I only got CLI

The attached phpt runs with the built-in webserver, and is
supposed to pass with PHP 5.6.x, but to fail for master.

> (Assigned it to you, to notice this comment)

Generally a good idea, as the bug tracker doesn't send mails to
all involved parties automatically (maybe something that could be
improved). However, I have explicitly subscribed to this ticket,
and I'll try to follow the discussion anyway. :)

[1] <https://github.com/php/php-src/commit/da7d94cd73a1f654bf49b16b5d1bf221255710de>
 [2015-07-04 03:10 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=550bbf8f4614a5c868010195f562be3e9ee6bb00
Log: Fixed bug #69983 (get_browser fails with user agent of null)
 [2015-07-04 03:10 UTC] laruence@php.net
-Status: Verified +Status: Closed
 [2015-07-07 23:36 UTC] ab@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=550bbf8f4614a5c868010195f562be3e9ee6bb00
Log: Fixed bug #69983 (get_browser fails with user agent of null)
 [2016-07-20 11:38 UTC] davey@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=550bbf8f4614a5c868010195f562be3e9ee6bb00
Log: Fixed bug #69983 (get_browser fails with user agent of null)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC