Published on: August 7, 2014 by Vipin R.N
The Client was trying to get Browser information of his site visitors using get_browser() function, but it didn’t work. Let us see how to fix the issue with browscap php extension
Browser Capabilities Project. Used to obtain Browser information and related statistics of Visitors to a website. The Native code used for this is :
$browser = get_browser();
Browscap is an advanced extension of HTTP Environment Variable HTTP_USER_AGENT
The issue was with the Browscap PHP extension. It was not available in the server. The server is running on CloudLinux, so things are quite different here in terms of PHP. CloudLinux has several features, PHP Selector is one among it. With the aid of PHP Selector, cPanel users can switch to PHP versions 5.2, 5.3, 5.4, 5.5 and other (native) versions if included in its configuration. Hence, the native location for PHP (in cPanel servers) at /usr/local/lib/php is not used in CloudLinux environment.
A smart range of Installation / Configuration docs are available here as well.
With reference to this topic it is possible to compile PHP extensions as we prefer. But Browscap PHP extension is not actually an extension that has to be configured. The library files were already available, we just had to know how to include it in the PHP configuration.
Following are the important file locations in CloudLinux environment for PHP :
|PHP 5.x Binary files||/opt/alt/php5x/usr/bin/|
|PHP 5.x Binary (CLI)||/opt/alt/php5x/usr/bin/php|
|PHP 5.x Binary (CGI)||/opt/alt/php5x/usr/bin/php-cgi|
|PHP 5.x Configuration||/opt/alt/php5x/etc/php.ini|
|PHP 5.x Configuration (Extensions)||/opt/alt/php52/etc/php.d.all/|
|PHP 5.x Modules||/opt/alt/php5X/usr/lib64/php/modules/|
* Replace x with appropriate version, for instance php52/php53/php54
The fix is quite simple. Download the Browscap configuration file from here and move it to /opt/alt/php5x/etc/php.d.all. Further edit the PHP configuration file /opt/alt/php5x/etc/php.ini and uncomment the following line :
[browscap] ;browscap = extra/browscap.ini
[browscap] browscap = /opt/alt/php5x/etc/php.d.all/browscap.ini
Save the file. Please note that you will have to do this for all PHP versions if it has to be made available globally.
Finally, restart CageFS parameters :
cagefsctl --rebuild-alt-php-ini cagefsctl --force-update
Test the PHP Code given earlier, it should give you the output like this
Detecing Browser … stdClass Object ( [browser_name_regex] => ^mozilla/5\.0 (.*linux i686.*).*gecko/.*firefox/.*$ [browser_name_pattern] => Mozilla/5.0 (*Linux i686*)*Gecko/*Firefox/* [parent] => Firefox Generic [platform] => Linux [win32] => [comment] => Firefox Generic [browser] => Firefox [alpha] => 1 [frames] => 1 [iframes] => 1 [tables] => 1 [cookies] => 1
=> 1 [javaapplets] => 1 [cssversion] => 3 [version] => 0.0 [majorver] => 0 [minorver] => 0 [platform_version] => unknown [beta] => [win16] => [win64] => [backgroundsounds] => [vbscript] => [activexcontrols] => [ismobiledevice] => [issyndicationreader] => [crawler] => [aolversion] => 0 )
Category : Howtos, Linux
Add new commentSIGN IN