Advertisement
modInfo

Untitled

Mar 16th, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.99 KB | None | 0 0
  1. <?php
  2.  
  3. $user_agent     =   $_SERVER['HTTP_USER_AGENT'];
  4.  
  5. function getOS($user_agent) {
  6.     $os_platform    =   "Unknown OS Platform";
  7.     $os_array       =   array(
  8.                             '/windows nt 6.2/i'     =>  'Windows 8',
  9.                             '/windows nt 6.1/i'     =>  'Windows 7',
  10.                             '/windows nt 6.0/i'     =>  'Windows Vista',
  11.                             '/windows nt 5.2/i'     =>  'Windows Server 2003/XP x64',
  12.                             '/windows nt 5.1/i'     =>  'Windows XP',
  13.                             '/windows xp/i'         =>  'Windows XP',
  14.                             '/windows nt 5.0/i'     =>  'Windows 2000',
  15.                             '/windows me/i'         =>  'Windows ME',
  16.                             '/win98/i'              =>  'Windows 98',
  17.                             '/win95/i'              =>  'Windows 95',
  18.                             '/win16/i'              =>  'Windows 3.11',
  19.                             '/macintosh|mac os x/i' =>  'Mac OS X',
  20.                             '/mac_powerpc/i'        =>  'Mac OS 9',
  21.                             '/linux/i'              =>  'Linux',
  22.                             '/ubuntu/i'             =>  'Ubuntu',
  23.                             '/iphone/i'             =>  'iPhone',
  24.                             '/ipod/i'               =>  'iPod',
  25.                             '/ipad/i'               =>  'iPad',
  26.                             '/android/i'            =>  'Android',
  27.                             '/blackberry/i'         =>  'BlackBerry',
  28.                             '/webos/i'              =>  'Mobile'
  29.                         );
  30.     foreach ($os_array as $regex => $value) {
  31.  
  32.         if (preg_match($regex, $user_agent)) {
  33.             $os_platform    =   $value;
  34.         }
  35.  
  36.     }  
  37.     return $os_platform;
  38. }
  39.  
  40. function getBrowser($user_agent) {
  41.     $browser        =   "Unknown Browser";
  42.     $browser_array  =   array(
  43.                             '/msie/i'       =>  'Internet Explorer',
  44.                             '/firefox/i'    =>  'Firefox',
  45.                             '/safari/i'     =>  'Safari',
  46.                             '/chrome/i'     =>  'Chrome',
  47.                             '/opera/i'      =>  'Opera',
  48.                             '/netscape/i'   =>  'Netscape',
  49.                             '/maxthon/i'    =>  'Maxthon',
  50.                             '/konqueror/i'  =>  'Konqueror',
  51.                             '/mobile/i'     =>  'Handheld Browser'
  52.                         );
  53.  
  54.     foreach ($browser_array as $regex => $value) {
  55.  
  56.         if (preg_match($regex, $user_agent)) {
  57.             $browser    =   $value;
  58.         }
  59.     }
  60.     return $browser;
  61. }
  62.  
  63.  
  64. $user_os        =   getOS($user_agent);
  65. $user_browser   =   getBrowser($user_agent);
  66.  
  67. $device_details =   "<strong>Browser: </strong>".$user_browser."<br /><strong>Operating System: </strong>".$user_os."";
  68.  
  69. print_r($device_details);
  70.  
  71. echo("<br /><br /><br />".$_SERVER['HTTP_USER_AGENT']."");
  72.  
  73. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement