Jump to content

Is it possible to find out what browser you use with PHP?


Anders Moen

Recommended Posts

The reason why I want to use PHP, is because then I can use a header redirect.. I mean, I could have done it like this:

<!--[if IE><?php header('Location: ie.php'); ?><![endif]-->

over the doctype, but then the site I'm working on wouldn't be valid. Anyone who knows?The reason I don't want it to be done with JS or just that, is because well, then people can just stop the whole thing and view the site wrong.

Link to comment
Share on other sites

That may also redirect some web crawlers. You might want to look at various user agent strings to see what they send, but some things like msnbot send a string like "MSIE compatible". Additionally, various versions of Mozilla, Netscape, and Opera also include "MSIE" in the user agent string. If all you are checking is for the text "MSIE" in the user agent string, you're going to get a ton of false positives. It's better to use get_browser, and check something like the browser element of the returned array. It will be more reliable then checking for a substring in the user agent string. Look at the get_browser page for examples.If you want a list of everything that has "MSIE" in it, go here:http://www.pgts.com.au/pgtsj/pgtsj0208c.htmlClick on something like section 1 and search the page for "MSIE".

Link to comment
Share on other sites

Thanks for your reply justsomeguy. I don't really care about that, because it's not my site lolEdit:I found another way to do it too maybe:

<?phpif (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {?>Make the menu for stupid IE users (lol, no offence but I just hate MS)<?php}else { ?>Make the menu for those who use a browser that's good like Opera :)<?php}?>

Link to comment
Share on other sites

""OFF TOPIC""First: Even if it's not your site, I'll guess that's you that's writing the page (or helping someone do it..), nomather what you should do it in the "correct" or best way (not always the simplest). If you do things right and in a good way (also behave nicely etc..), you get a good reputation (can give you more clients or a job..), if you do things in the "wrong" or in a "bad way", you get a bad reputation (= hard to get customers etc..).Remember that! Always try to do things right etc..Second: (this builds somewhat on the first..) Most IE users aren't stupid (perhaps "ignorant"/"uninformed", but not stupid). Most IE users us IE because IE comes installed by default, and they don't that they can, or how to, install other browsers. Some users use IE because they are forced (by the IT-department on their comapny [there's alot things you can say about IT-departments...]). There's also users who use IE by choice (who are wellinformed etc..), there's things that you can say about them that's perhaps isn't the nicest things you can say about someone, but I'm not gonna say anything of that..So, you shouldn't call IE users stupid, because most of them isn't, they just don't know that there's something better (or can't use it..). I've talked with people that thinks that IE (and the blue E) is the only way to internet (or even that that is internet...), but they aren't stupid, they just haven't the knowledge...Then you could remove the word "users" so it'd say "IE is stupid.", 'cause IE is stupid (the "stupideness" of the IE development team can be discussed... :) ), It doesn't follow standard etc (the latest, IE 7, is the best of the versions, but not good enough yet. Will it ever be??). IE has given me alot of headakes..I can't get what the IE developers are thinking, there's a standard and I can't why it should be so hard to follow standards (other browsers do it...).

Link to comment
Share on other sites

If it's only IE you want to target, I think the best approach remains conditional comments. If you need to do a redirect, you could use a meta redirect (that is, with the <meta/> element). Sure, IE users might turn off meta redirects, but if they are clever enough/allowed to do that, they'll be clever enough/allowed to get another browser.

Link to comment
Share on other sites

Thanks for your reply justsomeguy. I don't really care about that, because it's not my site lol
Hmm. So should I stop helping out on this forum, because these projects aren't mine? People don't give recommendations for people who only do the bare minimum, and if a potential client is using Netscape or something, and you send them IE code, and the site looks messed up, are those people going to want to hire you? I mean, it's your choice, you can do what you want, I'm just trying to tell you what the better way is. If you're trying to determine what the browser is, checking for text in a user agent string is not the best way to do it. The presence of 4 letters in the user agent string doesn't say anything about what browser they are using. And trust me, I have Opera identify itself as IE all the time when I reach a poorly-designed site that only allows IE and does a check on the user agent string. It's real easy to put "MSIE" in the user agent string, it doesn't mean I'm using IE.
Edit:I found another way to do it too maybe:
<?phpif (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {?>Make the menu for stupid IE users (lol, no offence but I just hate MS)<?php}else { ?>Make the menu for those who use a browser that's good like Opera :)<?php}?>

That's the same way as the first.Seriously, how hard is it to do this right?
$browser = get_browser();if ($browser->browser == "IE"){}else{}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...