You are here: Re: parsing useragent string without get_browser « PHP « IT news, forums, messages
Re: parsing useragent string without get_browser

Posted by "I. Gray" on 08/25/05 17:45

The problem is I haven't seen any examples of this in php.

The best I have come up with is the following. I know the code is pants,
but it works. I am sure people out there can think of a better way of
doing it-

$ua = $logInfo[useragent];
if ( ereg("Firefox/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}",
$ua, $array)) {$browser = $array[0];}
if ( ereg("MSIE [0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}",
$ua, $array)) {$browser = $array[0];}
if (
ereg("Bloglines/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua,
$array)) {$browser = $array[0];}
if (
ereg("Amfibibot/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua,
$array)) {$browser = $array[0];}
if ( ereg("msnbot/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}",
$ua, $array)) {$browser = $array[0];}
if (
ereg("Googlebot/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua,
$array)) {$browser = $array[0];}
if ( ereg("Safari/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}",
$ua, $array)) {$browser = $array[0];}
if (
ereg("Konqueror/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}", $ua,
$array)) {$browser = $array[0];}
if ( ereg("Netscape/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}",
$ua, $array)) {$browser = $array[0];}
if (
ereg("Thunderbird/[0-9]{1,2}[\.]{0,1}[0-9]{0,4}[\.]{0,1}[0-9]{0,4}",
$ua, $array)) {$browser = $array[0];}
if (strpos($ua, "Web RSS Reader")!== FALSE) {$browser = "Web RSS
Reader";}
if (strpos($ua, "BDFetch")!== FALSE) {$browser = "BDFetch";}
if (strpos($ua, "www.almaden.ibm.com/cs/crawler")!== FALSE) {$browser
= "Web Fountain";}
if (strpos($ua, "sohu-search")!== FALSE) {$browser = "Sohu Search";}
if (strpos($ua, "Yahoo! Slurp")!== FALSE) {$browser = "Yahoo! Slurp";}
if (strpos($ua, "Windows NT 5.1")) {$platform = "Windows XP";}
elseif (strpos($ua, "Windows NT 5.0")) {$platform = "Windows 2000";}
elseif (strpos($ua, "Windows 98") OR strpos($ua, "Win98")) {$platform
= "Windows 98";}
elseif (strpos($ua, "Windows 95") OR strpos($ua, "Win95")) {$platform
= "Windows 95";}
elseif (strpos($ua, "Win16") OR strpos($ua, "Windows 3.1")) {$platform
= "Windows 3.1";}
elseif (strpos($ua, "Mac OS X")) {$platform = "Mac OSX";}
elseif (strpos($ua, "Linux")) {$platform = "Linux";}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация