Question

I recently started to use the get_browser() function inside of PHP and I encountered a major issue. I am trying to return the browser that the user is using back to the user but when I run the code:

$browser = get_browser(null, true);
print($browser['browser']);

It returns 'DefaultBrowser'. I updated my Browscap.ini file and specified the location in my php.ini file but it seemed to change nothing. Any solutions, I am very new to PHP. Thanks

Was it helpful?

Solution

Unfortunately the browscap.ini file is not updated as often as browsers (which is very very often, these days). Fortunately, you can just edit the file yourself and copy-paste the newest browsers that are in there, and then increment the version number. Generally the capabilities will be the same or better, so it shouldn't cause problems.

[EDIT]

The browscap.ini file contains entries like

[IE 10.0]
Parent=DefaultProperties
Comment="IE 10.0"
Browser="IE"
Version=10.0
MajorVer=10
MinorVer=0
Beta=true
Win32=true
Frames=true
IFrames=true
Tables=true
Cookies=true
BackgroundSounds=true
JavaScript=true
VBScript=true
JavaApplets=true
ActiveXControls=true
CssVersion=3

[Mozilla/*(*MSIE 10.*Windows NT 6.1*64*Trident/6.0*)*]
Parent=IE 10.0
Platform="Win7"
Platform_Version=6.1
Win32=false
Win64=true

A general entry for the version, plus a number of entries for specific platforms. You can just copy these, change the version from 10 to 11, and then add them to the file.

So those two entries would become

[IE 11.0]
Parent=DefaultProperties
Comment="IE 11.0"
Browser="IE"
Version=11.0
MajorVer=11
MinorVer=0
Beta=true
Win32=true
Frames=true
IFrames=true
Tables=true
Cookies=true
BackgroundSounds=true
JavaScript=true
VBScript=true
JavaApplets=true
ActiveXControls=true
CssVersion=3

[Mozilla/*(*MSIE 11.*Windows NT 6.1*64*Trident/6.0*)*]
Parent=IE 11.0
Platform="Win7"
Platform_Version=6.1
Win32=false
Win64=true
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top