Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get_browser() returns FALSE

Tags:

php

browscap

- Running PHP 5.3.8 on Linux-

To start, we have solved this issue to the point where the function returns the expected values. However there are still a lot of unanswered questions I've got, and the "solution" is more of a hack-around than anything.

I've spent the better part of a day on this issue, so bear with me as I explain what was done. To start, the issue is that the return value of get_browser() is FALSE, which is not a documented return value. This leads me to assume that FALSE being returned means some sort of error state within the function.

The test code, after many iterations, became just a simple var_dump(get_browser($agent, true)). I ran tests with both passing the user agent string directly, as well as passing no arguments, e.g. var_dump(get_browser()), that all had the same return values.

What was tried/verified, with no change in return value:

browscap.ini:

  • Have the latest version, also tested a few previous versions

Permissions:

  • bowscap.ini - Initial permissions were 644, but I have tried everything from 644-777

  • Directory containing browscap.ini - Initial permissions were 755, tried 777 as well

  • Verified that PHP can access the file and directory with other functions like file()

User Agent

  • Tried passing a manual user agent string

  • Tried passing $_SERVER['HTTP_USER_AGENT']

  • Verified my user agent string with a friend in a far away land - get_browser() returned values as expected.

php.ini

  • The browscap setting points to the correct location

  • verified again with echo count(file(ini_get('browscap')));

Error Logs

  • Checked PHP & Apache error logs for any mention of 'browscap' or anything even closely related - nothing out of the ordinary.

File Structure

This is where I suspect that the error comes from. browscap.ini lives in /var/php/, which has suitable permissions as noted above. My thought was that maybe PHP couldn't access this directory, or something along those lines. However, this directory is also where sessions are stored, so that becomes less likely.

THE "SOLUTION"

What solved the issue was moving browscap.ini to the public web directory. I'm curious as to why this is the case, especially given the undocumented return value. The "solution" works, but is not the solution I thought I would find...

Does get_browser() have special permissions requirements, or anything like that? file() could access the directory and file just fine, but get_browser() could not (presumably). I've practically pulled my hair out over this issue and would love some resolution!

Thanks for reading!

like image 468
orourkek Avatar asked May 08 '12 23:05

orourkek


2 Answers

I had the exact same issue as the original poster. The solution? php.ini required an absolute path to the browscap.ini file.

So, even though PHP found the file and it appeared in phpinfo()'s output, the following line was the problem:

browscap = browscap.ini

With that line, getBrowser() returned false.

However, changing it to an absolute path worked, like so:

browscap = /etc/browscap.ini

Hope this helps someone! It's a strange one...

like image 56
Mark Locker Avatar answered Oct 30 '22 01:10

Mark Locker


You have tried around every required method.

http://php.net/manual/en/function.get-browser.php having note:

In order for this to work, your browscap configuration setting in php.ini must point to the correct location of the browscap.ini file on your system.

browscap.ini is not bundled with PHP, but you may find an up-to-date php_browscap.ini file here.

While browscap.ini contains information on many browsers, it relies on user updates to keep the database current. The format of the file is fairly self-explanatory.


What solved the issue was moving browscap.ini to the public web directory.

It is may be pointing to that location. i.e. public web directory

Does get_browser() have special permissions requirements, or anything like that?

Read permissions are required only.

like image 35
Somnath Muluk Avatar answered Oct 30 '22 00:10

Somnath Muluk