$_SERVER['HTTP_USER_AGENT'] does not exist
  • I am trying to detect an iOS browser using PHP. The HTTP_USER_AGENT key does not seem to exist in $_SERVER array. Do you know if there is a way to enable it??

  • 5 Answers sorted by
  • Have you tried looking at the output of http://<site>.vaesite.com/?__phpinfo=1 to see the full list of keys and values available in $_SERVER?

  • This is interesting:

    1. HTTP_USER_AGENT in phpinfo() will not show up locally, but it will show up on staging.

    2. That variable show up in phpinfo() when viewed on a desktop, but not on an iPad.

    3. on Staging, when I actually pull that specific key tho, it will not show up.

  • 1. It may be that the local development environment doesn't sent the User-Agent header. If that's the case, then it's something we could potentially address in the next update. How critical is that?

    2. All I can think here is that some setting on your iPad is keeping it from sending the User-Agent header. How else would this happen? Have you tried on Safari on a desktop just to get the most apples-to-apples comparison?

  • Kevin-

    I did figure out a workaround: detecting the platform in Javascript and then setting a Cookie which the PHP code can read.

  • Well, I'm not sure why it wasn't working, but I'm happy that you gangstered up a solution.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion