How should I be setting browscap.ini file
Asked Answered
S

5

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

Scandent answered 30/9, 2012 at 17:20 Comment(6)
Restarting the browser might be insufficient. PHP runs in the local webserver. Restart that one.Congius
sorry, i meant i restarted server, i mistakenly typed browser, it should be server.Scandent
@mario, i dont know about time zone, i wanted to use get_browser which is not working.Scandent
@Congius i don't believe this is a duplicateHauler
@Baba: True. Not this one. Seems more like editing discrepancy now. (Would have otherwise closevoted as too localized.)Congius
Could this setting be changed during script execution, with ini_set?Insulting
H
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"
Hauler answered 30/9, 2012 at 17:41 Comment(2)
thanks. it worked, but default was extra\browscap.ini so there may be any alternative??Scandent
Yes, you can find several browscap alternatives at browscap.orgFlorenceflorencia
P
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"
Pumping answered 30/6, 2015 at 7:9 Comment(0)
B
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

Benildis answered 5/7, 2016 at 20:33 Comment(0)
U
3

This is work for me on MacBook.

[browscap]
; http://php.net/browscap
browscap = "/usr/local/etc/browscap.ini"
Undergrowth answered 19/8, 2016 at 17:14 Comment(0)
T
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.

Trinidadtrinitarian answered 5/9, 2021 at 17:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.