Home

See the related posts

PHP Warning: Call-time pass-by-reference has been deprecated    Working with Database (MySQL)    Cookies in PHP    Session Management Functions in php    Join array elements with a string – implode   

Detect Operating System Using PHP

We can get various informations such as the Browser Name, Version , Operating System etc from the PHP Variable

 $_SERVER['HTTP_USER_AGENT'] 

. This code will help you to Detect the operating used by the user to access your webpage. This will help you to deal the user in a better way. Happy Coding :)

<?php
      $operating_systems = array  (

              // User Agent String will have a information about Os. Lets identify them.

              'Windows 3.11' => 'Win16',

              'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)',

              'Windows 98' => '(Windows 98)|(Win98)',

              'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',

              'Windows XP' => '(Windows NT 5.1)|(Windows XP)',

              'Windows Server 2003 ' => '(Windows NT 5.2)',

              'Windows Vista ' => '(Windows NT 6.0)',

              'Windows 7' => '(Windows NT 7.0)',

              'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',

	      'Windows ME' => '(Windows 98)|(Win 9x 4.90)|(Windows ME)',

              'Open BSD' => 'OpenBSD',

              'Sun OS' => 'SunOS',

              'Linux' => '(Linux)|(X11)',

              'Mac OS' => '(Mac_PowerPC)|(Macintosh)',

              'QNX' => 'QNX',

              'BeOS' => 'BeOS',

              'OS/2' => 'OS/2',

      );

      // Match against our array of operating systems, To match

      foreach($operating_systems as $current_os=>$found)

      {

              if (eregi($found, $_SERVER['HTTP_USER_AGENT']))

              {

                      // Found the OS cheers ....

                      break;

              }

      }

     	//echo $_SERVER['HTTP_USER_AGENT'];

      echo "You are using ".$current_os;
?>

Home

See the related posts

PHP Warning: Call-time pass-by-reference has been deprecated    Working with Database (MySQL)    Cookies in PHP    Session Management Functions in php    Join array elements with a string – implode   

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment