Detect User Operating System in PHP

Its been along time since my last post, always got new things to learn and share. Now i’m gonna share how to detect user’s OS with php with the code below :


$pos = strpos($_SERVER["HTTP_USER_AGENT"], “Windows”);

if ($pos == true) {
echo “Your OS is Windows”;
}else{
echo “Others”;
}

just print_r($_SERVER) and you’ll see many information about the server that you are using and one of it is about the operating system. Function strpost is to find the position of string in a string, for more complete information you can search it in google. If $pos is true which mean contain the string you want then it runs the function you want or else not. Hope all of this can help you. Thanx.

Leave a Reply

Your email address will not be published. Required fields are marked *