Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

carlosbutler

macrumors 6502a
Original poster
Feb 24, 2008
691
2
When I say advanced, I mean one that works properly:rolleyes:

After reading many tutorial sites and forums on the subject, as well as Firefox documentation (or something along those lines) it turns out that all browsers are rubbish at picking up which browser you are using.

I was hoping someone could end up doing a script in PHP or JS (preferably in PHP since some have JS turned off) that would easily allow coders to pick up when users with certain browsers access a site. Lets say for example, telling users using IE anything to upgrade and get a better browser:p.

If anyone has any suggestions, i am sure it would not only help me but many people who are stumped by this.
 
The only browser sniffing I'm doing currently is for IE with some JavaScript. I use it to simply provide a message to users of < IE8.

PHP:
if (navigator.appName.indexOf("Microsoft") != -1&&
parseFloat(navigator.appVersion.split("MSIE")[1]) < 8.0)

This gets around users who have changed their browser agent as well.
 
is that PHP or Javascript? im guessing Javascript but you might have some strange php code:p

how would you actually go about implementing something like that? since, as i said, i have looked around tutorials and things and arent really that useful. even the php.net site (for once) was not that great

i think this needs to be cleared up and the companies need to sort them selves out
 
is that PHP or Javascript? im guessing Javascript but you might have some strange php code:p

how would you actually go about implementing something like that? since, as i said, i have looked around tutorials and things and arent really that useful. even the php.net site (for once) was not that great

i think this needs to be cleared up and the companies need to sort them selves out

It's JavaScript, I just like the color coding from the PHP vb Code markup. I place the code at the top of the content section of my page layout (which is automatically included on every page using PHP includes) and do a document.write that simply outputs some verbage about how I don't support IE. It's generally not advised to do too much browser sniffing as it's generally not needed. If you want to see my implementation just check out my site that is in my profile and do a view source.

There's a bit of a story behind the browser agents and their evolution, though it doesn't make you feel much better knowing the dirty history.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.