browscap ini directive not set

冷暖自知 提交于 2019-11-27 11:13:12
Pascal MARTIN

I don't think this is the "best" solution to detect is a browser supports what you need for your website :

  • first of all, browsers can lie -- they can send whatever thay want as User-Agent
    • And even if a given version of a support should support what you need, Javascript can still be disabled.
  • second, there are more "proper" way to detect what a browser can do or not, when it comes to Javascript.

For the second point, you should test if the browser actually supports what you need -- and not rely on a list such as the browscap one.


Still, to answer your question about browscap : there is a note at the bottom of the manual page for get_browser that says (quoting) :

Note: In order for this to work, your browscap configuration setting in php.ini must point to the correct location of the browscap.ini file on your system. browscap.ini is not bundled with PHP, but you may find an up-to-date » php_browscap.ini file here.
While browscap.ini contains information on many browsers, it relies on user updates to keep the database current. The format of the file is fairly self-explanatory.

So, you have to :

  • download the browscap file,
  • and set the browscap directive in your php.ini file, so it points to the file you downloaded.

I know this topic is old, but you can use something like:

<noscript>JavaScript must be enabled</noscript>

to display if JavaScript is not enabled.

You can check the browser by using Browser class download it from Github

Configuration

      include(/your-path/Browser.php);
$browser = new Browser();
    if( $browser->getBrowser() == Browser::BROWSER_IE && $browser->getVersion() >= 8 ) 
        {
            echo "Your browser is Internet explorer version 8";                                                                                                                                    
    }

There is a bug in PHP that can also result in this error when the real problem is that the web server can't read the browscap file (e.g., if it's owned by root instead of www-data). See https://bugs.php.net/bug.php?id=74501

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!