By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

why $_SERVER['HTTP_USER_AGENT'] gives different result in Mozilla and MSIE?

P: 5
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.   <title>PHP Test</title>
  4. </head>
  5. <body>
  6. <?php echo $_SERVER['HTTP_USER_AGENT']; ?> 
  7. </body>
  8. </html>
when i have running the above code on my system,it gives two different result in Mozilla & MSIE Browser.I couldn't understand why?please guide me.?

the result in Mozilla is:-Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/2008070208 Firefox/3.0.1

the result in MSIE is:-Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)

Sep 9 '08 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 8,639
This is because FF and IE are two different browsers (i.e.: user agents). A browser can set this string to any value it likes (e.g. Opera can identify itself as IE) but usually it gives properties of the browser (OS, browser language, name, rendering engine,...)

Sep 9 '08 #2

Expert 5K+
P: 5,058
This is exactly the purpose of the $_SERVER['HTTP_USER_AGENT'] element; to identify the user agent (a.k.a. the browser) the request was sent from.

Read the results you posted and you will see that each string is built to identify the browser, it's version and various other useful info.

Please use [code] tags when posting you code examples.

Thank you.
Sep 9 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.