views:

145

answers:

5

Let's say for example I wanted to echo "You are using Windows!" or "You are using Macintosh!", depending on the users OS. Is this possible?

+6  A: 

You can look at the user agent string, which often includes information about the OS.

Note, however, that there are operating systems other than Windows and OS X.

David Dorward
+1  A: 

http://phpcode.mypapit.net/detect-ip-location-operating-system-and-browser-using-php-detector-library/46/

The library is handy for for creating web application which serve content depending on users location and type of operating system/browser that he use or for creating web application that collect web surfers statistical data.

code example:

  require('detector.php');
  $dip = &new Detector($_SERVER["REMOTE_ADDR"], $_SERVER["HTTP_USER_AGENT"]);

  echo "$dip->town";

  echo "$dip->state, $dip->ccode,$dip->town, ($dip->ipaddress) ";

  echo "using : $dip->browser $dip->browser_version on $dip->os $dip->os_version";
Steav
+9  A: 

By analyzing $_SERVER['HTTP_USER_AGENT'] it's possible to tell what system (and browser) the user is claiming to use.

It's easily spoofable, though.

ZJR
+1 for easily spoofable and for explaining how to retrieve the user agent string.
Michael Aaron Safyan
+1  A: 

Yes it is possible.

You want to use $_SERVER['HTTP_USER_AGENT'] which holds information about the user's operating system and browser.

You can use this resource to look up user agent strings (which are held in that variable).

However, it is possible for browsers to spoof this information so you can't assume that this is reliable.

Rupert
+8  A: 

Try the get_browser() function that's built into PHP.

$browser = get_browser(null, true);
echo "Platform: " . $browser["platform"] . "\n"; 
Bill Karwin