25

I downloaded the browscap.ini file and then pasted it to the directory "C:\wamp\bin\php\php5.4.3\extras" and i went to php.ini file and made these changes there:

[browscap]
; http://php.net/browscap
browscap = extras/browscap.ini

and then i restarted the server, and typed the following code into temp.php file:

<?php
echo $_SERVER['HTTP_USER_AGENT'] . "<br><br>";

$browser = get_browser(null, true);
print_r($browser);
?>

now the output is like:

Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4

Warning: get_browser(): browscap ini directive not set in C:\wamp\www\functions\browser.php on line 4

am i missing something? please provide some solution, and sorry if i am unable to make you understand

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nicholas Wild
  • 629
  • 1
  • 6
  • 17

5 Answers5

33

You are to use the Full PATH and restart your server when you are done

Example

[browscap]
; http://php.net/browscap
browscap = "C:\xampp\php\extras\browscap.ini"
Baba
  • 94,024
  • 28
  • 166
  • 217
15

on linux server

wget http://browscap.org/stream?q=Lite_PHP_BrowsCapINI -O /etc/php.d/browscap.ini

[browscap]
; http://php.net/browscap
browscap = "/etc/php.d/browscap.ini"
Roninio
  • 1,761
  • 1
  • 17
  • 24
4

use this code for install, tested on mint and debian

wget http://browscap.org/stream?q=Lite_PHP_BrowsCapINI -O /etc/php7/apache2/browscap.ini
sudo echo -e "[browscap]\n  browscap = '/etc/php7/apache2/browscap.ini'" >> php.ini
sudo service apache2 reload

replace php7 for you PHP version

Bruno Ribeiro
  • 1,280
  • 16
  • 21
3

This is work for me on MacBook.

[browscap]
; http://php.net/browscap
browscap = "/usr/local/etc/browscap.ini"
0

Note: browsecap file is not default configuration, and disabled by default. If you setting it, make sure you call get_browser() safely in your scripts to avoid warnings on other installations by checking if it is available to be called:

if (!ini_get('browscap')) {

    // Not set, use other custom func to detect browser:
    $browser = get_browser_manually();
} else {

    // Browsecap.ini was set, use it:
    $browser = get_browser(null, true);
}

See my complete answer related to broswer detection here.

Alex Khimich
  • 788
  • 9
  • 10