- 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!
browsecap
was inphi.ini
. Was it the full path/var/php/browsecap.ini
or relativebrowsecap.ini
? or were you changing it throughout your testing? – Chamaeleonecho count(file(ini_get('browscap')));
, which returned the expected result. This means thatfile()
could open and read the file just fine, soget_browser()
should have been able to as well. – Amourpropre