首页 » 技术分享 » Tech Stuff - Mobile Browser ID (User-Agent) Strings

Tech Stuff - Mobile Browser ID (User-Agent) Strings

 

Tech Stuff - Mobile Browser ID (User-Agent) Strings

The non-mobile stuff is here (hint: you get jerked back by the power cord after 3 feet and your arms start to ache after 10 minutes with non-mobile stuff) or click on any right menu link for the browser/section.

We started these pages with four strings because we had never seen a comprehensive list anywhere. Nominally RFC 1945 and RFC 2068 define them (get RFCs) but only as an afterthought (the RFCs define HTTP 1.0 and 1.1). Browser IDs, more correctly User Agent IDs, appear, among other places, as the environmental variable HTTP_USER_AGENT in Apache. You need this information to make the fewest checks possible for the browser environment or to optimise the display or ... to know who and what is crawling around your site. And if you want to check your browser string use our cheap trick page.

New Stuff: FF and Chrome inch forward by about 1 version number per month or so, but the big ground shaker is Version 11 of Microsoft Explorer. And it has an amazing string including the words "like Gecko" in it. Apparently, MS ran into problems of page rendering when they tried to use version 11 (think of all those browser detection scripts return version 1 by jove). So they dropped the version number (well moved it elsewhere in the string) and adopted the Chrome strategy of using "like Gecko". Waterfox is a natively 64-bit version of Firefox - Intel's optimized 64-bit compiler, compatible with 32-bit extensions....runs like the wind. Did we mention it was also fast?

Department of useless stuff: Anyone know the difference between Open Mini and Mobile...no it's not the beginning of a joke. One of our smart readers responded with a link to Opera's site which says - roughly - that Opera Mobile is a real browser that can directly access the web - just like regular Opera and is designed for smartphones whereas Opera Mini is a cut-down browser that needs an Opera server and is typically used on feature phones. So there you go.

As always thanks to everyone who took the time to supply a string - even if we didn't use it.

The end of an era: The last version of Netscape - the browser that started the modern browser business is no more. Netscape is dead - long live Netscape (with appropriate shudders at the memory of NS 4.x).

Getting the Strings for Nefarious Purposes (and in Other Formats)

Note: The title is our normal (and puerile) attempt at humor. Plenty of folk want to use the strings for sensible and useful reasons. But that would make a boring title. You are perfectly at liberty to use the strings for any purpose you choose.

We regularly get asked for these strings in other formats - mostly without all our pathetic attempts at humor in the explanations. We had studiously avoided doing anything because it smelled, vaguely, of work. Then we got an email from Marc Gray who suggested that we use a simple regular expression and was even kind enough to supply it. Marc provided a php script, which we enclose below (with a minor correction supplied by Dave Thomas) for those to whom it may be a more sensible solution (a formatted list based on this script is available here, credits and their script at the foot of the page). We slapped together a few lines of Javascript (you can't actually code in JS you can only slap things together - doubtless google would disagree) based on his idea so if you light the blue touch paper by clicking the button below, this page will disppear (after about 10 to 20 secs - depending on the speed of your processor) only the raw strings will remain. Simply save the resulting page and hack out anything that looks vaguely HTML'ish (the strings are enclosed in <p class="g-c-s"></p> tags). (view javascript here) It was tested and works with FF (3 and 4), Webkit (Chrome/Safari), Opera 11.x (works on small data sets, croaks on the whole page), and IE 9.0 & even IE 10 (IE 8.0 does not work, which probably means all prior versions don't work either). We are progressively going to add the feature on a browser-by-browser basis for your delight, edification and titillation. To restore the page to its full glory(!) just hit your page refresh button.

Note: We removed a bunch of annoying <br /> tags that were lying around inside the browser strings from our old page formatting method.

// Marc Gray's PHP script (untested by us)
// use at your discretion
<?php
$page = file_get_contents('http://www.zytrax.com/tech/web/mobile_ids.html');
preg_match_all('/<(p) class="g-c-[ns]"[^>]*>(.*?)<\/p>/s', $page, $m); 

$agents = array();
foreach($m[2] as $agent) {
  $split = explode("\n", trim($agent));
  foreach($split as $item) {
    $agents[] = trim($item);
  }
}
// $agents now holds every user agent string, one per array index, trimmed
foreach($agents as $agent) {
 echo($agent."\n");
}

?>

Notes:

  1. We always send an email to thank you for your contribution - if you don't get one it's 'cos your spam filters are probably putting it in your junk folder (thanks a bundle) or 'cos you gave us a wrong return address 'cos you don't trust us (thanks a bundle).

  2. As always - especially if you are feeling a super-sleuth moment coming on - have look at the mystery strings and strings from server logs to add to the total of mankind's knowledge.

  3. We discontinued the crawler, spiders and robots section - there is much better coverage at this site which is the home of robots.txt which is, as you all know, the file that tells well behaved crawlers to 'keep out' of your dirty linen.

  4. We used to publish the feature list for mobile things dating from the days when it would probably say something like - 'makes phone calls, 15 char display, weighs 6 pounds'. Now the spec list just leaves us with a feeling of inferiority (they are smarter than we are) and it takes about 6 hours to get the specs from these horrible 'graphic-overkill' mobile supplier web sites. So we stopped.

For browser historians: We thought that Mosaic was the original browser. As usual we were wrong. James Butler took the time to drop us an email - thanks:

Before there was NSCA's Mosaic there were several other browsers capable of interpreting HTML, including Erwise and Viola, both of which I used before the Andreeson project issued any software. Although primarily for viewing SGML, both of those browsers did a pretty good job of parsing the very basic HTML commands that Mr. Berners-Lee published as he developed his SGML subset (HTML).

转载自原文链接, 如需删除请联系管理员。

原文链接:Tech Stuff - Mobile Browser ID (User-Agent) Strings,转载请注明来源!

0