/    Sign up×
Community /Pin to ProfileBookmark

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:

[code=php]
if (/*browser is opera or a mac browser*/)
{
// Opera and mac stuff here
}
else
{
// all other browsers
}
[/code]

Any ideas?

Cheers

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@bokehJul 09.2006 — Yes. It´s pretty simple but why would you want to do such a thing? It is agains the ideology of the web.
Copy linkTweet thisAlerts:
@cybercampbellauthorJul 09.2006 — 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
Copy linkTweet thisAlerts:
@AmazingAntJul 09.2006 — 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 [URL=http://www.php.net/manual/en/function.get-browser.php]get_browser()[/URL] function. It has the ability to show much more than just the browser's name, so you'd need something to this effect:
[code=php]
$browser = get_browser(null, true);
$browsername = $browser['browser']
if ($browsername == "Opera")
{
//whatever it does for opera//
}else {
//whatever it does otherwise//
}
[/code]


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 [I]should[/I] do the trick.
Copy linkTweet thisAlerts:
@bokehJul 09.2006 — 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.
Copy linkTweet thisAlerts:
@AmazingAntJul 09.2006 — That's a very [i]valid[/i] point. Which is why I use IE, Firefox, and Opera to view every page I make before letting other people get at it.
Copy linkTweet thisAlerts:
@cybercampbellauthorJul 10.2006 — 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 [URL=http://www.php.net/manual/en/function.get-browser.php]get_browser()[/URL] 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 [I]should[/I] do the trick.[/QUOTE]


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.[/QUOTE]

I understand bokeh but I can't find a simple wysiwyg that works properly in Opera. do you know of one?

Cheers
Copy linkTweet thisAlerts:
@AmazingAntJul 10.2006 — Cheers AmazingAnt...any idea about the mac part?

Cheers[/QUOTE]

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 [i]should[/i] 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.
Copy linkTweet thisAlerts:
@bokehJul 10.2006 — do you know of one[/QUOTE]The majority of these are years out of date and write garbage code. Personally I always use a text editor.
Copy linkTweet thisAlerts:
@AmazingAntJul 10.2006 — wow... and I thought you were a bad person, guess I was wrong... ?
Copy linkTweet thisAlerts:
@cybercampbellauthorJul 10.2006 — And, I can't return the cheers because I don't have a drink with me right now.[/QUOTE]

Cheers....an Australian thing ?
×

Success!

Help @cybercampbell spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...