Page 1 of 1
How do I tell what browser is being used?
Posted: Tue Jan 14, 2014 10:50 am
by simonmlewis
Code: Select all
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";
This always produces this, even in Internet Explorer 10:
[text]Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; MASBJS; rv:11.0) like Gecko [/text]
Why, and how do I show if it is IE, Firefox, Opera etc..?
Re: How do I tell what browser is being used?
Posted: Tue Jan 14, 2014 10:58 am
by Celauran
I get different results for each.
Firefox: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:26.0) Gecko/20100101 Firefox/26.0
Chrome: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
Safari: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11
Re: How do I tell what browser is being used?
Posted: Tue Jan 14, 2014 11:03 am
by simonmlewis
Code: Select all
<?php
$browser = $_SERVER["HTTP_USER_AGENT"];
echo "$browser";
?>
I jsut rang this in a browser.php file - away from any other code.
And I get this:
[text]Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; MASBJS; rv:11.0) like Gecko[/text]
In IE 10.
Re: How do I tell what browser is being used?
Posted: Tue Jan 14, 2014 11:06 am
by simonmlewis
What i've done is add it a web site that gets a lot of traffic, to see what browsers are being used, but for some reason, although varied results (in the brakcets) they all show Mozilla/5.0. SO this isn't down to my machine.
Re: How do I tell what browser is being used?
Posted: Tue Jan 14, 2014 11:08 am
by Celauran
You can see my examples above also all start with Mozilla/5.0 and yet are still distinguishable.
Re: How do I tell what browser is being used?
Posted: Tue Jan 14, 2014 11:10 am
by Celauran
Re: How do I tell what browser is being used?
Posted: Tue Jan 14, 2014 11:16 am
by simonmlewis
OH hell I see what you mean, so that's why they all start with Mozilla.
I'm trying to conjour up a code that INSERTS to be database, "Firefox", Chrome" or whatever, but I don't think that's gona be possible. It would have to be that fill string.
Re: How do I tell what browser is being used?
Posted: Tue Jan 14, 2014 11:25 am
by Celauran
Firefox has 'Firefox' in the UA string. Ditto for Chrome and Safari. Check IE and Opera, I'm sure it's easy enough.
Re: How do I tell what browser is being used?
Posted: Tue Jan 14, 2014 1:12 pm
by simonmlewis
Maybe - I guess if I do a prematch to pick out certain words, like as many browsers as I can think of, that should do it.
Re: How do I tell what browser is being used?
Posted: Tue Jan 14, 2014 1:15 pm
by Christopher
There are a number of good libraries in PHP and Javascript that do this browser check for you. Search the web for them.
Re: How do I tell what browser is being used?
Posted: Tue Jan 14, 2014 1:22 pm
by simonmlewis
Which part of this identifies it as Internet Explorer?
Code: Select all
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; MASBJS; rv:11.0) like Gecko
Re: How do I tell what browser is being used?
Posted: Tue Jan 14, 2014 1:39 pm
by requinix
"
Trident".
"MSIE" is another keyword to search for.
Re: How do I tell what browser is being used?
Posted: Wed Jan 15, 2014 2:50 am
by simonmlewis
Is there a web site/page that lists ALL these keyterms, as I'd never known Trident was Internet Explorer.
Maybe it's best I just leave my code as is.
Re: How do I tell what browser is being used?
Posted: Wed Jan 15, 2014 9:05 am
by Christopher
Try get_browser()