How do I get the browser name using PHP? I thought this would be straightforward? All I need to do is differentiate between IE and Firefox.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
But! Don’t!
There is rarely a good reason to be sniffing user-agent at the server side. It brings a bunch of problems, including:
browsers and other user-agents that lie about who they are, or strip the user-agent header completely, or generally make it hard to distinguish what the real browser is from the header text. For example the above rule will also detect Opera when it’s spoofing IE, and IEMobile (Windows Mobile), which you may or may not want as it is a very different browser to desktop IE.
if you discriminate on the user-agent at the server-side, you must return a
Vary: User-Agentheader in the response, otherwise proxies may cache a version of the page and return it to other browsers that don’t match. However, including this header has the side-effect of messing up caching in IE.Depending on what it is you are trying to achieve, there is almost always a much better way of handling the differences between IE and other browsers at the client side, using CSS hacks, JScript or conditional comments. What is the real purpose for trying to detect IE in your case?