Hey PHP masters,
I just started on php not too long ago. I was wondering is there a way to detect which browser the user is using with PHP?
Thanks.
PHP browser detect.
Started by Power, Nov 24 2005 01:04 AM
6 replies to this topic
#1
Posted 24 November 2005 - 01:04 AM
#2
Posted 24 November 2005 - 01:38 AM
Simply, by using
<?php $browser = $_SERVER["HTTP_USER_AGENT"]; echo 'Your Browser is: '. $browser; ?>
Edited by Chaos King, 24 November 2005 - 01:47 PM.
#3
Posted 24 November 2005 - 02:52 AM
Hey Chaos King, look a little closer at your code, you'll notice that we don't usually name a variable that shows the browser "ip" 
And we also don't say, Your ip is firefox, yip
And we also don't say, Your ip is firefox, yip
Edited by HaloprO, 24 November 2005 - 02:52 AM.
#4
Posted 24 November 2005 - 02:52 AM
#5
Posted 24 November 2005 - 01:47 PM
hehehe...
My bad, was reading two topics at the same time. Kinda got both the requests mixed up.
My apologies.
My bad, was reading two topics at the same time. Kinda got both the requests mixed up.
My apologies.
#6
Posted 25 November 2005 - 02:25 AM
Well... still helped me a lil bit.
#7
Posted 29 November 2005 - 07:30 AM
Umm i found this on php.net the other day and it works a treat
echo $info[browser];
$browser = array (
"MSIE", // parent
"OPERA",
"MOZILLA", // parent
"NETSCAPE",
"FIREFOX",
"SAFARI"
);
$info[browser] = "OTHER";
foreach ($browser as $parent) {
$s = strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent);
$f = $s + strlen($parent);
$version = substr($_SERVER['HTTP_USER_AGENT'], $f, 5);
$version = preg_replace('/[^0-9,.]/','',$version);
if (strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent)) {
$info[browser] = $parent;
$info[version] = $version;
}
}
if ($info[browser] == "MOZILLA") {
$info[browser] = "FIREFOX";
}
echo $info[browser];
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
