PHP:在共享主机上使用 browscap.ini。 - ini_set() 失败
我正在尝试使用 get_browser() ,不幸的是我的页面位于共享主机上,并且我无法访问 php.ini。
我已经下载了最新版本的 browscap.ini 并将其放置在我的文档根目录中。然后我添加了以下内容:-
if (!ini_set('browscap', '/home/私有内容/browscap.ini')) {
echo "设置浏览器失败";
} 否则{
回声“browscap = [”。 ini_get('browscap') 。 “]”;
}
退出();
但这失败了,(注意:失败条件的 echo 语句始终显示 [] - 即使我没有 browscap.ini 文件,该设置仍应显示在 ini_get 中......不是吗?)
我已经查看了之前的问题,但它们似乎没有帮助,有什么想法吗?
I'm trying to use get_browser() , unfortunately my page is on a shared host, and I have no access to php.ini.
I have downloaded the latest version of browscap.ini and placed in my document root. I have then added the following:-
if (!ini_set('browscap', '/home/private stuff/browscap.ini')) {
echo "Failed to set browscap";
} else {
echo "browscap = [" . ini_get('browscap') . "]";
}
exit();
But this fails, (nb: the echo statement for the failed condition always shows [] - even if I didn;t have the browscap.ini file the setting should still show up in the ini_get.... shouldn't it?)
I have looked at the previous questions on this and they don't seem to help, any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 PHP 手册,“browscap”仅在系统 php.ini 和/或 httpd.conf。您不能在脚本级别设置它。
As per the PHP manual, 'browscap' is changeable only in the system php.ini and/or httpd.conf. You cannot set it at the script level.
我以前没有听说过此功能,但在 谷歌搜索我发现phpbrowscap(之前位于此 Google 代码存储库< /a>( 这是一个独立的类,您应该能够在托管环境中使用它。作者支持许多配置文件和 快速入门(之前为此处)看起来特别容易。
I hadn't heard of this feature before, but in Googling around I came across phpbrowscap (previously at a this Google Code repo( which is a standalone class that you should be able to use in your hosted environment. The author supports many configuration files and the QuickStart (previously here) looks especially easy.