User Agent String Decipher...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • henryrhenryr
    New Member
    • Jun 2007
    • 103

    User Agent String Decipher...

    Hi

    I am trying to write a function to decode / decipher the user agent string. I've got so far but I wondered if anyone knows any quick ways to do this or any useful resources to help me finish. I have tried searching to little avail.

    Here's my present code:

    [code=php]

    function decipher_agent( $in) {
    $out['string']=$in;
    if ($l= strpos(' '.$in,'MSIE')) {
    $out['browser']='IE';
    $l=$l+5;
    $f=$l+3;
    $out['version']=substr(' '.$in,$l,$f);
    }
    elseif ($l= strpos(' '.$in,'Firefox' )) {
    $out['browser']='FireFox';
    if ($t= strpos(substr($ in,$l),'2.')) {
    $out['version']='2';
    }
    elseif ($t= strpos(substr($ in,$l),'1.')) {
    $out['version']='1';
    }
    }
    if ($l= strpos(' '.$in,'Windows' )) {
    $out['os']='Windows';
    $t= substr($in,$l);
    if (strpos(' '.$t,'6')) {
    $out['version']='Vista';
    }
    elseif (strpos(' '.$t,'5')) {
    $out['version']='XP';
    }
    elseif (strpos(' '.$t,'4')) {
    $out['version']='2K';
    }
    else {
    $out['version']=substr($t,8,11 );
    }
    }
    elseif ($l= strpos(' '.$in,'Mac')) {
    $out['os']='Mac';
    if (strpos(' '.$in,'OS X')) {
    $out['version']='OS X';
    }
    else {
    $out['version']=null;
    }
    }
    elseif ($l= strpos(' '.$in,'Linux')) {
    $out['os']='Linux';
    $out['version']=null;
    }
    else {
    $out['os']='Unknown OS';
    }
    return $out;
    }
    [/code]

    Not so pretty ;) Any pointers much appreciated.

    Henry
  • nitinpatel1117
    New Member
    • Jun 2007
    • 111

    #2
    Your code is already quite short in achieving this task.

    But these may help a bit.


    Comment

    Working...