skip to Main Content

I need to pass user agent value into front end.

I can get this value using $_SERVER['HTTP_USER_AGENT'] and write it into front end.
(Actually I will be using Mage::helper('core/http')->getHttpUserAgent(), but I think it’s just a magento helper to call above mentioned function.)

Or I can use get navigator.userAgent with js on client side.

Which better and why? My primary concern is speed.

p.s. I understand that UA can be easily manipulated. We are not basing any serious functionality on the value, it’s used as a secondary parameter.

2

Answers


  1. I would personally use navigator.userAgent. Mainly, because passing values from PHP to JavaScript is pretty ugly in my opinion. Also, the value will be exactly the same for both. Even if someone decides to edit their useragent.

    I think simplicity takes the cake here.

    Login or Signup to reply.
  2. Performance will depend on the purpose. If you need this inside php, then use the server variable with helper getter you mentioned above. For js use navigator object.

    In general both navigator.userAgent and HTTP_USER_AGENT are variables of Request Header and are both already present in memory (of server or users browser in case of js). So no measurable performance difference is possible.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search