Click to See Complete Forum and Search --> : browser detect
cybercampbell
07-09-2006, 06:19 PM
Hi all
I'm wanting to detect the browser so I can show different content if the visitor is using "Opera" or any Mac browser.
like this sort of thing:
if (/*browser is opera or a mac browser*/)
{
// Opera and mac stuff here
}
else
{
// all other browsers
}
Any ideas?
Cheers
bokeh
07-09-2006, 06:38 PM
Yes. Itīs pretty simple but why would you want to do such a thing? It is agains the ideology of the web.
cybercampbell
07-09-2006, 06:42 PM
the reason is that i'm using a wysiwyg text area and it doesn't work on opera or on a mac so rather then have a unusable dead page i'de like to provide a standard text area so those users can atleast use the site
AmazingAnt
07-09-2006, 06:54 PM
Well, i'd like to say that that's not exactly nice that it doesn't want to work in opera, but yea... You can take a look at the get_browser() (http://www.php.net/manual/en/function.get-browser.php) function. It has the ability to show much more than just the browser's name, so you'd need something to this effect:
$browser = get_browser(null, true);
$browsername = $browser['browser']
if ($browsername == "Opera")
{
//whatever it does for opera//
}else {
//whatever it does otherwise//
}
Thus, the get_browser function is grabbing data about the user's browser, and putting it into $browser as an array. Then, the part of the array named 'browser' is set as the value of $browsername. Then, you just check to see if $browsername is equal to Opera or not.
That should do the trick.
bokeh
07-09-2006, 06:56 PM
Write valid code and you won't have any trouble. What you are considering should not be done. Opera works just fine on valid code.
AmazingAnt
07-09-2006, 06:57 PM
That's a very valid point. Which is why I use IE, Firefox, and Opera to view every page I make before letting other people get at it.
cybercampbell
07-09-2006, 07:01 PM
Well, i'd like to say that that's not exactly nice that it doesn't want to work in opera, but yea... You can take a look at the get_browser() (http://www.php.net/manual/en/function.get-browser.php) function. It has the ability to show much more than just the browser's name, so you'd need something to this effect:
Thus, the get_browser function is grabbing data about the user's browser, and putting it into $browser as an array. Then, the part of the array named 'browser' is set as the value of $browsername. Then, you just check to see if $browsername is equal to Opera or not.
That should do the trick.
Cheers AmazingAnt...any idea about the mac part?
Write valid code and you won't have any trouble. What you are considering should not be done. Opera works just fine on valid code.
I understand bokeh but I can't find a simple wysiwyg that works properly in Opera. do you know of one?
Cheers
AmazingAnt
07-09-2006, 07:08 PM
Cheers AmazingAnt...any idea about the mac part?
Cheers
Well, no not really. I'm not even sure that checking the variable for "Opera" will always work, because (since you know the page won't work in opera, i'm assuming you have a copy of it, on your computer) opera can be set to disguise itself as IE or Firefox. I'm not sure this is still true for 9.0, but the version I have lets you do that.
As for on a Mac, I won't beable to confirm what to look for with php, at least until sometime around christmas when I buy myself a 17" Mac Book Pro. You should however, beable to detect the client's OS with JavaScript. If you're determined to use php however, you might want to find a friend who has a Mac, and see what the get_browser thing says that their browser is. Then, you could add that into the anti-Opera check.
And, I can't return the cheers because I don't have a drink with me right now.
bokeh
07-09-2006, 07:27 PM
do you know of oneThe majority of these are years out of date and write garbage code. Personally I always use a text editor.
AmazingAnt
07-09-2006, 07:29 PM
wow... and I thought you were a bad person, guess I was wrong... :D
cybercampbell
07-09-2006, 07:30 PM
And, I can't return the cheers because I don't have a drink with me right now.
Cheers....an Australian thing :)