Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

How To Get The User's Browser And Operating System's Informations


1 reply to this topic

#1 nirvaman

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 210 posts
  • Gender:Male
  • Location:Localhost
  • myCENT:12.94

Posted 31 December 2010 - 01:07 PM

Hi to all
After a long time , i came today with a script that will help you get and show the users browse and os informations on your webpage.
Here we go:
<?php

$agent = $_SERVER['HTTP_USER_AGENT']; 

$browserArray = array(
        'Windows Mobile' => 'IEMobile',
'Android Mobile' => 'Android',
'iPhone Mobile' => 'iPhone',
'Firefox' => 'Firefox',
        'Google Chrome' => 'Chrome',
        'Internet Explorer' => 'MSIE',
        'Opera' => 'Opera',
        'Safari' => 'Safari'
); 
foreach ($browserArray as $k => $v) {

    if (preg_match("/$v/", $agent)) {
         break;
    } else {
 $k = "Browser Unknown";
    }
} 
$browser = $k;

$osArray = array(
        'Windows 98' => '(Win98)|(Windows 98)',
        'Windows 2000' => '(Windows 2000)|(Windows NT 5.0)',
'Windows ME' => 'Windows ME',
        'Windows XP' => '(Windows XP)|(Windows NT 5.1)',
        'Windows Vista' => 'Windows NT 6.0',
        'Windows 7' => '(Windows NT 6.1)|(Windows NT 7.0)',
        'Windows NT 4.0' => '(WinNT)|(Windows NT 4.0)|(WinNT4.0)|(Windows NT)',
'Linux' => '(X11)|(Linux)',
'Mac OS' => '(Mac_PowerPC)|(Macintosh)|(Mac OS)'
); 
foreach ($osArray as $k => $v) {

    if (preg_match("/$v/", $agent)) {
         break;
    } else {
 $k = "Unknown OS";
    }
} 
$os = $k;
// Now you can do whatever you wanna do with the users browser and os informations for example
echo '<h1>User Browser and Operating System</h1>';
echo $agent;
echo "<h2>You are using: <em>$browser - $os</em></h2>";
?>

Try the code and if you do like it , they drope me a thank ;)

#2 mahesh2k

    Trap Double Mocha Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 2,347 posts
  • Gender:Male
  • Location:Valley of Darkness
  • myCENT:27.17
  • Spam Patrol

Posted 01 January 2011 - 02:41 AM

I always prefer JS behind the site's background for knowing this information. Infact most of the analytics site use this method to understand the user and browser behavior. I never came across any script that shows browser information using PHP code or java code. So thanks for sharing this on forum.




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users