Jump to content

Recommended Posts

Help guys!!!

Basically i want to return/display User OS info/name from input field...

Below my unfinished scripts..

 

<?php

$user_agent     =   $_SERVER['HTTP_USER_AGENT'];

function getOS() { 

    global $user_agent;

    $os_platform    =   "Unknown OS Platform";

    $os_array       =   array(
                            '/windows nt 6.2/i'     =>  'Windows 8',
                            '/windows nt 6.1/i'     =>  'Windows 7',
                            '/windows nt 6.0/i'     =>  'Windows Vista',
                            '/windows nt 5.2/i'     =>  'Windows Server 2003/XP x64',
                            '/windows nt 5.1/i'     =>  'Windows XP',
                            '/windows xp/i'         =>  'Windows XP',
                            '/windows nt 5.0/i'     =>  'Windows 2000',
                            '/windows me/i'         =>  'Windows ME',
                            '/win98/i'              =>  'Windows 98',
                            '/win95/i'              =>  'Windows 95',
                            '/win16/i'              =>  'Windows 3.11',
                            '/macintosh|mac os x/i' =>  'Mac OS X',
                            '/mac_powerpc/i'        =>  'Mac OS 9',
                            '/linux/i'              =>  'Linux',
                            '/ubuntu/i'             =>  'Ubuntu',
                            '/iphone/i'             =>  'iPhone',
                            '/ipod/i'               =>  'iPod',
                            '/ipad/i'               =>  'iPad',
                            '/android/i'            =>  'Android',
                            '/blackberry/i'         =>  'BlackBerry',
                            '/webos/i'              =>  'Mobile'
                        );

    foreach ($os_array as $regex => $value) { 

        if (preg_match($regex, $user_agent)) {
            $os_platform    =   $value;
        }

    }   

    return $os_platform;

}

function getBrowser() {

    global $user_agent;

    $browser        =   "Unknown Browser";

    $browser_array  =   array(
                            '/msie/i'       =>  'Internet Explorer',
                            '/firefox/i'    =>  'Firefox',
                            '/safari/i'     =>  'Safari',
                            '/chrome/i'     =>  'Chrome',
                            '/opera/i'      =>  'Opera',
                            '/netscape/i'   =>  'Netscape',
                            '/maxthon/i'    =>  'Maxthon',
                            '/konqueror/i'  =>  'Konqueror',
                            '/mobile/i'     =>  'Handheld Browser'
                        );

    foreach ($browser_array as $regex => $value) { 

        if (preg_match($regex, $user_agent)) {
            $browser    =   $value;
        }

    }

    return $browser;

}


$user_os        =   getOS();
$user_browser   =   getBrowser();

$device_details =   "<strong>Browser: </strong>".$user_browser."<br /><strong>Operating System: </strong>".$user_os."";

print_r($device_details);

//detail
//echo("<br /><br /><br />".$_SERVER['HTTP_USER_AGENT']."");
?>

Above scripts works well when I run it...
It will display my OS version

But the problem it is, I want to create an input field so user can key in any IP address and the scripts above will display the OS info/name if valid else invalid...

 

Above scripts use.. $user_agent = $_SERVER['HTTP_USER_AGENT']; that automatically display OS info/name...

But I want manually key in the IP from input field and the scripts above will display correspond OS info/name from the input field...

how to change scripts above...especially  $user_agent = $_SERVER['HTTP_USER_AGENT']; so it can return IP address from input field??

 

I`m greatly honor if you guys would like to help out.. :(
 

Alright. First off, please stop saying "IP". This has absolutely nothing to do with IP addresses... unless...

 

Exactly what are you entering? An IP address? Or a user-agent string? If you're thinking that you can enter an IP address and detect their operating system, you are very wrong.

Ok I`ll will explain to you detail of what i`m trying to achieve...

I have a list of IP(sorry) on my network...and I have succeed ping out all the ranges of IP from table list...

So what I trying to figure is how to display their OS name???

I dont know how to do...I`ve to search out about $user_agent...but i dont know how to used it...

i`ll also have try diff function including gethostbyaddr,gethostbyname,etc but with my host, it succed but other host not succed..:(

 

If i`ll use $user_agent how to do it to display OS name of my list of network host???

Thank for your concern...it been hour try to search at diff forum,google but not succed....
 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.