PHP 

Use below PHP code to detect Operating System

<?php

function getPlatform() {
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    $platform = 'Unknown';

    //Get the platform
    if (preg_match('/linux/i', $u_agent)) {
        $platform = 'linux';
    } elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
        $platform = 'mac';
    } elseif (preg_match('/windows|win32/i', $u_agent)) {
        $platform = 'windows';
    }
    
    return $platform;
}

echo getPlatform();
?>

Output

windows

Thanks for reading.

Tags:

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on JEE Tutorials | TwitterFacebook Google PlusLinkedin | Reddit

Leave a Reply

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