Check/Get Visitors Browser/Operating Systems details in PHP
Hello Friends,
There are plenty of browsers(Mozilla Firefox , Internet Explorer , Google Crome , Safari , Opera and many more) and Operating systems (Windows , Linux , Unix and many more) available in web world. It might be a case when you want to get browser/operating system details of visitors or users who came across your website built up with PHP and fill up a contact request form. Browser/Operating System details will help you to analyze the contact us request made by visitor or user. By looking at browser info & Operating system info,you have a brief idea about users before replying them.
If you want to track visitor's or user's browser details than you may use get_browser() PHP function which is a very easy to remember also. But here i am sharing a function from which you will get a filtered data(only useful details). Below is the function and answer of all those people who want to know "How to get Browser/Operating system details in PHP".
function check_browser()
{
$browsers = "mozilla msie gecko firefox ";
$browsers.= "konqueror safari netscape navigator ";
$browsers.= "opera mosaic lynx amaya omniweb";
$browsers = split(" ", $browsers);
$userAgent = strtolower( $_SERVER['HTTP_USER_AGENT']);
$l = strlen($userAgent);
for ($i=0; $i
{
$browser = $browsers[$i];
$n = stristr($userAgent, $browser);
if(strlen($n)>0)
{
$version = "";
$navigator = $browser;
$j=strpos($userAgent, $navigator)+$n+strlen($navigator)+1;
for (; $j<=$l; $j++)
{
$s = substr ($userAgent, $j, 1);
if(is_numeric($version.$s) )
$version .= $s;
else
break;
}
}
}
if (strpos($userAgent, 'linux')) {
$platform = 'linux';
}
else if (strpos($userAgent, 'macintosh') || strpos($userAgent, 'mac platform x')) {
$platform = 'mac';
}
else if (strpos($userAgent, 'windows') || strpos($userAgent, 'win32')) {
$platform = 'windows';
}
return array(
"browser" => $navigator,
"version" => $version,
"platform" => $platform,
"userAgent" => $userAgent);
}$browserdata = check_browser();
$browser_with_version = $browserdata['browser'].' '.$browserdata['version'];
$operating_system = $browserdata['platform'];
You need to call simply check_browser() and you will get the specific data of browser details with version and operating system details. Comment below if you find any problem.
To know more about programming,JavaScript issues,jQuery,Expression Engine,MYSQL database and Open-source, enter your email address below. We will send you free tutorials.
Posts Related to Check/Get Visitors Browser/Operating Systems details in PHP
Problem in Mozilla Firefox-Easy AJAX Pagination Using JQuery CakePHP
Hello Friends, I was working with CakePHP's Easy AJAX Pagination Using JQuery. I found this as a great code for sorting and paging with jQuery in ...
How to send email from localhost(XAMPP or WAMP) in PHP in Windows
Hello Friends, Whenever you works in local server (XAMPP or WAMP) for developing any email functionality in website, than you might be wonder that why ...
Export MYSQL data into Excel/CSV via php
Hello Friends, Today i came across a functionality where i need to Export the MYSQL data into CSV/Excel file via PHP function/script. There are such ...
Sending email with multiple attachment using php’s mail() function
Hello Friends, All we know how to send email in php. You might not be aware with sending email with attachment in php. If so ...
POP3/IMAP Email with attachment-Read & Forwarding with PHP
Hello Friends, Do you know how we can read, forward or transfer the POP3/IMAP email to another email address ? I came across this situation. ...
You can leave a response or trackback from your own site.






I am
about 1 year ago
Hi Rakshit,
Thanks for sharing the wonderful piece of code. It works great but probably unfortunately got missed for Chrome and also for Safari it gives wrong version.
I have modified it to work for these two also as following:
0)
{
$version = “”;
$navigator = $browser;
$j=strpos($userAgent, $navigator)+$n+strlen($navigator)+1;
for (; $j0){
break;
}
if($browser==’safari’ && strlen($n)>0){
$pos = strpos($userAgent,$browser);
if($pos>6){
$version_pos = $pos-6;
$version = substr($userAgent,$version_pos,5);
}
}
}
if (strpos($userAgent, ‘linux’)) {
$platform = ‘linux’;
}
else if (strpos($userAgent, ‘macintosh’) || strpos($userAgent, ‘mac platform x’)) {
$platform = ‘mac’;
}
else if (strpos($userAgent, ‘windows’) || strpos($userAgent, ‘win32′)) {
$platform = ‘windows’;
}
return array(
“browser” => $navigator,
“version” => $version,
“platform” => $platform,
“userAgent” => $userAgent);
}
$browserdata = check_browser();
$browser_with_version = $browserdata['browser'].’ ‘.$browserdata['version'];
$operating_system = $browserdata['platform'];
?>
about 7 months ago
It’s not works for me can you please help me.
I am getting the following error
Parse error: parse error in C:\wamp\www\enc-dec-with-key\user_agent_via_php.php on line 11