Identificare Browser e Sistema operativo di client in php

Browser

function GetBrowser()
{
    $browser = array(
        'MSIE'      => 'Internet Explorer',
        'Firefox'   => 'FireFox',
        'Lynx'      => 'Lynx',
        'Opera'     => 'Opera',
        'WebTV'     => 'WebTV',
        'Konqueror' => 'Konqueror',
        'bot'       => 'Bot',
        'Google'    => 'Bot',
        'slurp'     => 'Bot',
        'scooter'   => 'Bot',
        'spider'    => 'Bot',
        'infoseek'  => 'Bot',
        'Nav'       => 'Netscape',
        'Gold'      => 'Netscape',
        'x11'       => 'Netscape',
        'Netscape'  => 'Netscape'
    );
 
    foreach($browser as $chiave => $valore)
    {
        if(strpos($_SERVER['HTTP_USER_AGENT'], $chiave ))
        {
            return $valore;
        }
    }
 
    return 'Altro';
}

OS

function GetSistemaOperativo()
{
    $os = array(
        'Windows NT 5.1'  => 'Windows XP',
        'Windows NT 5.0'  => 'Windows 2000',
        'Windows NT 4.90' => 'Windows ME',
        'Win95'           => 'Windows 95',
        'Win98'           => 'Windows 98',
        'Windows NT 5.2'  => 'Windows NET',
        'WinNT4.0'        => 'Windows NT',
        'Mac'             => 'Mac',
        'PPC'             => 'Mac',
        'Linux'           => 'Linux',
        'FreeBSD'         => 'FreeBSD',
        'SunOS'           => 'SunOS',
        'Irix'            => 'Irix',
        'BeOS'            => 'BeOS',
        'OS/2'            => 'OS/2',
        'AIX'             => 'AIX',
    );
 
    foreach($os as $chiave => $valore)
    {
        if(strpos($_SERVER['HTTP_USER_AGENT'], $chiave))
        {
            return $valore;
        }
    }
 
    return 'Altro';
}

Leave a Reply

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