Is it possible to determine which operating system the user is using using PHP? (Mac or windows)

Say, for example, I wanted to repeat "You are using Windows!" or “You are using a Macintosh!”, depending on the users OS. Is it possible?

+4
source share
5 answers

Try the get_browser() function built into PHP.

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

Analyzing $_SERVER['HTTP_USER_AGENT'] , we can say that the system (and browser ) that the user requires to use.

It is easy to fake.

+14
source

You can see the user agent line, which often includes information about the OS.

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

+6
source

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

The library is convenient for creating a web application that serves content depending on the location of users and the type of operating system / browser used, or for creating a web application that collects statistics of web surfers.

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"; 
+1
source

Yes it is possible.

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

You can use this resource to search for user agent strings (which are stored in this variable).

However, browsers can spoof this information, so you cannot assume that it is reliable.

+1
source

Source: https://habr.com/ru/post/1307375/


All Articles