Javascript 未设置 browscap ini 指令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2036956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 22:30:35  来源:igfitidea点击:

browscap ini directive not set

phpjavascriptinibrowscap

提问by Robert Hurst

I'm using the get_browser()function in an attempt to warn people that their browser doesn't support Javascript. Actually I'm using it to tell them they can use certain parts of a web application I'm building. I've decided to properly use Javascript because I'm tired of listening to developers that are scared of using it and I've seen some great potential in the language. I digress, here is the error.

我正在使用该get_browser()函数试图警告人们他们的浏览器不支持 Javascript。实际上,我用它来告诉他们他们可以使用我正在构建的 Web 应用程序的某些部分。我决定正确使用 Javascript,因为我厌倦了听取害怕使用它的开发人员的意见,而且我已经看到了该语言的一些巨大潜力。我离题了,这是错误。

browscap ini directive not set

未设置 browscap ini 指令

Now I'd imagine this means I need somthing set it the php.ini. Can someone give me some direction on this one?

现在我想这意味着我需要将其设置为 php.ini。有人可以给我一些指导吗?

回答by 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.
  • 首先,浏览器可以撒谎——他们可以发送任何想要的东西 User-Agent
    • 即使给定版本的支持应该支持您所需要的,Javascript 仍然可以被禁用。
  • 其次,当涉及到 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.

对于第二点,您应该测试浏览器是否真的支持您所需要的——而不是依赖于诸如 browscap 之类的列表。


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


不过,回答你的问题有关browscap:有在为手动页面底部的说明get_browser,上面写着(引用)

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

注意:为了使其工作,您browscap在 php.ini 中的配置设置必须指向browscap.ini系统上文件的正确位置。browscap.ini未与 PHP 捆绑,但您可能会找到最新的? php_browscap.ini文件在这里。
虽然browscap.ini包含许多浏览器的信息,但它依赖于用户更新来保持数据库最新。该文件的格式是不言自明的。

So, you have to :

所以,你必须:

  • download the browscap file,
  • and set the browscapdirective in your php.inifile, so it points to the file you downloaded.
  • 下载浏览器文件,
  • browscap在您的php.ini文件中设置指令,使其指向您下载的文件。

回答by Jeremy Harris

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.

如果未启用 JavaScript,则显示。

回答by Manju

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

您可以使用 Browser 类从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";                                                                                                                                    
    }

回答by David Patterson

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

当真正的问题是 Web 服务器无法读取 browscap 文件(例如,如果它由 root 而不是 www-data 拥有)时,PHP 中有一个错误也会导致此错误。见https://bugs.php.net/bug.php?id=74501