5

I have just tried enabling php_browscap.ini so that I can use the get_browser function.

However, it seems to display an empty array?

$user_agent = get_browser(null, true);

print_r($user_agent);

In my php.ini file, I have the following:

[browscap]
; http://php.net/browscap
browscap = C:/wamp/bin/php/php5.3.0/extra/php_browscap.ini

I am probably missing something simple?

Update

Output I get:

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 ) 
Abs
  • 56,052
  • 101
  • 275
  • 409
  • Did you restart the web server? – Pekka Jan 08 '11 at 17:46
  • Yes, I restarted my web server. – Abs Jan 08 '11 at 17:48
  • 1
    please enable error reporting to see if there is a warning like `Warning: get_browser(): browscap ini directive not set` to make sure PHP really uses the browscap.ini – Gordon Jan 08 '11 at 18:00
  • Also use `phpinfo()` to make 100% sure you're editing the right php.ini, there can be multiple INIs present – Pekka Jan 08 '11 at 18:02
  • @Gordon - error reporting is on and no error reported. @Pekka - when I do a `phpinfo();` I can see the path of the browscap and it is correct. – Abs Jan 08 '11 at 18:56
  • I have edited my question to show my output. – Abs Jan 08 '11 at 18:56
  • @Abs that question might sound silly now, but you are doing the actual request with a browser and not from CLI, right? – Gordon Jan 08 '11 at 18:58
  • @Gordon - I am using a browser and not CLI. I tried it on FF3, Chrome and IE in case I had some settings somewhere in my browsers that I am not sending the user agent for some reason. – Abs Jan 08 '11 at 19:36

2 Answers2

2

You could find if there's something else failing using tools like ProcMon. This tool will tell you which files had been accessed, and what was the result. So, you have to open it, highlight the browsercap ini's path, restart the webserver and see if any of this scenarios fits:

  • File doesn't exist
  • Permission denied
  • Finding wrong path
  • Doesn't appear at all

ProcMon is a Wonderful tool if you're in Windows.

If you find any of those scenarios, and don't know what to do, just edit your question :-)

Good luck!

Gonzalo Larralde
  • 3,523
  • 25
  • 30
  • I used procmon and it does not show a read file operation on the path that browsecap.ini is on. But I don't think procmon will work as it will only show up as on apache process and won't give any specifics? – Abs Jan 08 '11 at 19:42
  • Procmon shows every access to the filesystem, so, if you don't see any reference there when you restart the web server, or try to access to the page that's using browsercap, then you have a configuration issue. Check restarting the server and loading the page with procmon opened. If nothing happens, then use phpinfo() to check that php is reading the configuration path correctly. – Gonzalo Larralde Jan 08 '11 at 20:18
  • This is a screen shot of procmon when I try to make use of get_browse: http://img406.imageshack.us/img406/1292/screenyg.png – Abs Jan 08 '11 at 21:03
  • Where is the access to the php file? Is it possible that firefox've asked the server if something changed and've used a cache? try with Ctrl + F5 and disable any server side cache. – Gonzalo Larralde Jan 08 '11 at 22:32
  • I always have firefox's cache off as its my dev browser. But I cleared my browsers cache and tried again, same thing! This problem is getting annoying now! :) – Abs Jan 08 '11 at 23:13
  • Try accessing it with other browser, or change something (adding an echo) in this page. Anyway, tray to print a phpinfo() and find browscap. Could you print a screenshot of it? – Gonzalo Larralde Jan 09 '11 at 00:57
1

There are several php.ini files for WAMP. To get to the right one, access it using the WAMP tray icon. That's how I got it to work. As it turns out, in my case it used the one in C:\Apps\wamp\bin\apache\apache2.2.22\bin.

Miel
  • 3,347
  • 2
  • 26
  • 39