note 101454 added to function.get-browser
| From: | curtlee2002 at gmail dot com | Date: | Fri, 17 Dec 2010 11:31:03 +0000 |
| Subject: | note 101454 added to function.get-browser | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175017@lists.php.net to get a copy of this message | ||
A modification to assadvirgo at gmail dot com's post to correctly identify Chrome / Chromium
browser. It would always be identified as Safari without this change.
<?php
function get_user_browser()
{
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$ub = '';
if(preg_match('/MSIE/i',$u_agent))
{
$ub = "IE";
}
elseif(preg_match('/Firefox/i',$u_agent))
{
$ub = "Firefox";
}
elseif(preg_match('/Safari/i',$u_agent))
{
if(preg_match('/Chrome/i',$u_agent))
{
$ub = "Chrome/Chromium";
}
else
{
$ub = "Safari";
}
}
elseif(preg_match('/Flock/i',$u_agent))
{
$ub = "Flock";
}
elseif(preg_match('/Opera/i',$u_agent))
{
$ub = "Opera";
}
return $ub;
}
echo $_SERVER['HTTP_USER_AGENT'] . '<br /><br />';
$browser = get_user_browser();
echo 'Browser: ' . $browser . '<br />';
?>
----
Server IP: 69.147.83.197
Probable Submitter: 139.78.10.24
----
Manual Page -- http://www.php.net/manual/en/function.get-browser.php
Edit -- https://master.php.net/note/edit/101454
Del: integrated -- https://master.php.net/note/delete/101454/integrated
Del: useless -- https://master.php.net/note/delete/101454/useless
Del: bad code -- https://master.php.net/note/delete/101454/bad+code
Del: spam -- https://master.php.net/note/delete/101454/spam
Del: non-english -- https://master.php.net/note/delete/101454/non-english
Del: in docs -- https://master.php.net/note/delete/101454/in+docs
Del: other reasons-- https://master.php.net/note/delete/101454
Reject -- https://master.php.net/note/reject/101454
Search -- https://master.php.net/manage/user-notes.php