dongren4099 2012-06-15 10:53
浏览 56
已采纳

Apache PHP HTTP_USER_AGENT和get_browser返回不正确的值

I am developing a corporate website for my HSC Software Design and Development Major Project. I have a section of code to check if the user's browser was supported in a MySQL database and, if not, display a warning to them and log their browser type. This code was working (almost) perfectly using the get_browser function, displaying a message that looked a bit like this:

We detected that you're using Internet Explorer to view this site. We have not tested this browser and cannot guarantee full support. For best results we recommend Google Chrome.

Since a bit of messing around in httpd.conf and a few server restarts however, this code no longer works. It detects ever browser as being "". (just an empty string) Trying to figure out the source of the problem, I put a quick debug line in:

echo $_SERVER['HTTP_USER_AGENT'];

For some reason this returns the following in EVERY BROWSER:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5

I would imagine that this is the cause of the problem, does anyone know why this might be?

  • 写回答

1条回答 默认 最新

  • douguai6716 2012-06-16 06:49
    关注

    Once again, the solution to my problem is very specific. Here is what the issue was:

    I use WebFaction for hosting, they have a applications, websites and domains setup which is great, but too complicated to fully explain here. Basically, I had been running the website successfully until one day the httpd executable randomly disappeared. After conversations with WebFaction's support team, I decided that I would rebuild Apache and put it in a new Application. Having done this my server was fixed and continued to run smoothly for a couple of weeks afterwards. A couple of days ago I decided it was time to clear out the old Application (which was inactive but still on the server) to regain a bit of disk space. What I didn't realise was that the PHP.ini in my new Application referred to the browscap.ini in my old Application. Once this had been deleted it could not be found anymore, returning errors. When I went to PHP.ini to check that I had the correct setting, I recognised the part that referred to my old Application because I was so used to it, and saw that the bit on the end was still correct, so assumed the problem could not be there.

    TL;DR, so long as no-one else screws up a migration they should not have this issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算