Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to detect what operating system a user is coming from using PHP? (mac or windows)

Tags:

php

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?

like image 582
Sabai Avatar asked Nov 27 '22 05:11

Sabai


2 Answers

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.

like image 64
ZJR Avatar answered Dec 01 '22 00:12

ZJR


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

$browser = get_browser(null, true);
echo "Platform: " . $browser["platform"] . "\n"; 
like image 44
Bill Karwin Avatar answered Nov 30 '22 22:11

Bill Karwin