Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Detect operating system from user agent string

This code uses an array of user strings and their matching operating systems so that it can detect what operatings system the user is using.

On Saturday, November 3rd 2007 at 02:02 AM
By Andrew Pociu (View Profile)
*****   (Rated 4.4 with 18 votes)
Contextual Ads
More PHP Resources
Advertisement
  1. $OSList = array
  2. (
  3.         // Match user agent string with operating systems
  4.         'Windows 3.11' => 'Win16',
  5.         'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)',
  6.         'Windows 98' => '(Windows 98)|(Win98)',
  7.         'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',
  8.         'Windows XP' => '(Windows NT 5.1)|(Windows XP)',
  9.         'Windows Server 2003' => '(Windows NT 5.2)',
  10.         'Windows Vista' => '(Windows NT 6.0)',
  11.         'Windows 7' => '(Windows NT 7.0)',
  12.         'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
  13.         'Windows ME' => 'Windows ME',
  14.         'Open BSD' => 'OpenBSD',
  15.         'Sun OS' => 'SunOS',
  16.         'Linux' => '(Linux)|(X11)',
  17.         'Mac OS' => '(Mac_PowerPC)|(Macintosh)',
  18.         'QNX' => 'QNX',
  19.         'BeOS' => 'BeOS',
  20.         'OS/2' => 'OS/2',
  21.         'Search Bot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp)|(MSNBot)|(Ask Jeeves/Teoma)|(ia_archiver)'
  22. );
  23.  
  24. // Loop through the array of user agents and matching operating systems
  25. foreach($OSList as $CurrOS=>$Match)
  26. {
  27.         // Find a match
  28.         if (eregi($Match, $_SERVER['HTTP_USER_AGENT']))
  29.         {
  30.                 // We found the correct match
  31.                 break;
  32.         }
  33. }
  34. // You are using Windows Vista
  35. echo "You are using ".$CurrOS;
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this code snippet
Comment Current Comments
by jack on Monday, June 9th 2008 at 04:16 AM

http://www.infysolutions.com

by josh on Monday, June 9th 2008 at 04:17 AM

<a href="http://www.infysolutions.com">infysolutions</a>

by STOP on Sunday, February 1st 2009 at 02:16 AM

STOP spamming us, idiots!

by Tom on Wednesday, April 15th 2009 at 10:36 AM

Line 11 should be

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


by cluke009 on Sunday, November 29th 2009 at 06:16 PM

The windows me detection is off a bit.

The fix below should do the trick

'windows-me' => '(Windows 98)|(Win 9x 4.90)',
'windows-98' => '(Windows 98)|(Win98)',

by cluke009 on Sunday, November 29th 2009 at 06:20 PM

Edit for the code above. This should cover all bases.

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

More info at: http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx

by Ali on Monday, June 14th 2010 at 06:41 AM

thanks :) , it worked

and this is an arabized version of the function:
http://me.the-ghost.com/2010/06/blog-post_14.html

by Ali on Monday, June 14th 2010 at 06:42 AM

thanks :) , it worked

and this is an arabized version of the function:
http://me.the-ghost.com/2010/06/blog-post_14.html


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs PHP Job Search
My skills include:

Enter a City:

Select a State:


Advanced Search >>
Sponsors
Discover Geekpedia

Other Resources