473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

User Agent String Decipher...

103 100+
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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. function decipher_agent($in) {
  3.     $out['string']=$in;
  4.     if ($l= strpos(' '.$in,'MSIE')) {
  5.       $out['browser']='IE';
  6.       $l=$l+5;
  7.       $f=$l+3;
  8.       $out['version']=substr(' '.$in,$l,$f);
  9.     }
  10.     elseif ($l= strpos(' '.$in,'Firefox')) {
  11.       $out['browser']='FireFox';
  12.       if ($t= strpos(substr($in,$l),'2.')) {
  13.         $out['version']='2';
  14.       }
  15.       elseif ($t= strpos(substr($in,$l),'1.')) {
  16.         $out['version']='1';
  17.       }
  18.     }
  19.     if ($l= strpos(' '.$in,'Windows')) {
  20.       $out['os']='Windows';
  21.       $t= substr($in,$l);
  22.       if (strpos(' '.$t,'6')) {
  23.         $out['version']='Vista';
  24.       }
  25.       elseif (strpos(' '.$t,'5')) {
  26.         $out['version']='XP';
  27.       }
  28.       elseif (strpos(' '.$t,'4')) {
  29.         $out['version']='2K';
  30.       }
  31.       else {
  32.         $out['version']=substr($t,8,11);
  33.       }
  34.     }
  35.     elseif ($l= strpos(' '.$in,'Mac')) {
  36.       $out['os']='Mac';
  37.       if (strpos(' '.$in,'OS X')) {
  38.         $out['version']='OS X';
  39.       }
  40.       else {
  41.         $out['version']=null;
  42.       }
  43.     }
  44.     elseif ($l= strpos(' '.$in,'Linux')) {
  45.       $out['os']='Linux';
  46.       $out['version']=null;
  47.     }
  48.     else {
  49.       $out['os']='Unknown OS';
  50.     }
  51.     return $out;
  52. }
  53.  
Not so pretty ;) Any pointers much appreciated.

Henry
Apr 1 '08 #1
1 4726
nitinpatel1117
111 100+
Your code is already quite short in achieving this task.

But these may help a bit.

http://www.dotvoid.com/view.php?id=68
http://www.texsoft.it/index.php?c=so...useragent&l=it
Apr 1 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

60
by: Fotios | last post by:
Hi guys, I have put together a flexible client-side user agent detector (written in js). I thought that some of you may find it useful. Code is here: http://fotios.cc/software/ua_detect.htm ...
3
by: LIN | last post by:
Hi, In my log files I often simple 'Mozilla' as UserAgent. In that case what may be the browser type. If Mozilla/4.0 is the UserAgent can we take it as a Netscape Browser. LIN
3
by: Amir Eshterayeh | last post by:
Dear Friends Would you please give me your professional idea about this asp.net problem. I need different virtual directory for different customer with their names like these:...
3
by: Raventhorn | last post by:
I am having problems that I also saw people having in the ASP.NET forums with menus and people coming to a site with weird user agent values. Is there a way to access the user agent before the user...
3
by: Allerdyce.John | last post by:
Hi, Is there an easy way in PHP which send outs different content depends on User Agent String value? If yes, is there an example/documentation? Thank you.
3
by: trynittee | last post by:
Hello, Thank you so much in advance to those who will take the time to read and answer. This group is a wonderful site. I have inherited a contacts database that sits on a server. Users...
0
by: =?Utf-8?B?TWlrZTEz?= | last post by:
Sorry for the cross post from dontnet.framework but I'm hoping this may see more activity here. I have written an application to access a web service. The application runs at multiple sites and...
0
by: =?Utf-8?B?TWlrZTEz?= | last post by:
Sorry for the cross post; I'm hoping this will get a response here... I have written an application to access a web service. The application runs at multiple sites and must cross a proxy server....
35
by: RobG | last post by:
Seems developers of mobile applications are pretty much devoted to UA sniffing: <URL: http://wurfl.sourceforge.net/vodafonerant/index.htm > -- Rob
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.