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?
views:
145answers:
5Is it possible to detect what operating system a user is coming from using PHP? (mac or windows)
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.
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";
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.
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.
Try the get_browser()
function that's built into PHP.
$browser = get_browser(null, true);
echo "Platform: " . $browser["platform"] . "\n";