I am curious to know if detecting the visitor browser with client-side script is more reliable than server-side script?
It is easy and popular to get the visitor browser both by PHP and Javascript. In the former one, we analyze $_SERVER['HTTP_USER_AGENT'] sent by the header array. However, header is not always reliable. Can Javascript be more reliable as it get the visitor browser from the visitor’s machine?
I mean is it possible to miss the USER AGENT in header and get the browser by javascript?
UPDATE: Please do not introduce methods such as jQuery as I am familiar with them. I just want to know if it’s possible for header’s user agent to fail when javascript still can detect browser? Comparison of client-side and server-side methods.
OK. So User-Agent header is not required by RFC
https://www.rfc-editor.org/rfc/rfc2616#section-14.43
Which means the server side detection is not guaranteed.
Similarly client side detection typically relies on
navigator.userAgentbut that is also provided by the user agent (browser or what not) and similarly cannot be guaranteed.Thus the answer to your question is 50/50 🙂
Now, if you are trying to figure out how to handle different browsers – feature detection is your safest bet here – but that’s a different question 😉