[ciapug] Browser Strings

Dave J. Hala Jr. ciapug@cialug.org
Thu, 14 Oct 2004 09:19:44 -0500


So, I've been fooling around trying to identify the web browser, the os
and if $MS the patch level. I've tried on with Mozilla on RHEL WS 3.x,
windows 95/98 win2k and XP... 

It's a crude function that gets the basics:


function parse_id($browser_id)
{
#
# Almost always the good stuff starts at the right paren. Convert it
# into a semi-colon to make it easier to explode the string into an
array
$new_id = str_replace("(", ";", $browser_id);
# sometimes MS doesn't use the right paren in the id string, and they
add extra stuff,
# remember embrace and extend?
# convert the right paran to a semi colon if it exits
$new_id = str_replace(")", ";", $new_id);
#echo "New id: $new_id <BR>";
# explode the values into an array
$info = explode(";", $new_id);
$cnt = count($info);
# cleanup the elements
for ($i=0;$i<$cnt;$i++){ $info[$i] = ltrim(rtrim($info[$i]));}
# element # 2 in the array is the browser identity string.
# however, mozilla and firefox put a U in there.Firefox
# identifiers end up in the elements 4 and 5, mozilla in 4,5,6
if($info[2] == 'U'){ $info[2] = "$info[4] $info[5] $info[6]";}
# windows 95/98 are reported as Windows 95 or Windows 98
# However 2000/Xp are reported as NT 5.0 or NT 5.1
# so clean it up
if($info[3]== "Windows NT 5.0"){ $info[3] = "Windows 2000";}
if($info[3]== "Windows NT 5.1"){ $info[3] = "Windows XP";}
# print out the results
for ($i=0;$i<$cnt;$i++){ echo "$i: $info[$i] <BR> ";}

return($info);

}

If anyone has any comments or ideas, I'd appreciate some feedback.

Also here's an interesting link:
http://www.hyperborea.org/journal/archives/2004/06/19/whats-in-a-user-agent-string/

:) Dave
-- 

Open Source Information Systems (OSIS)
Dave J. Hala Jr. <dave@osis.us>
641.485.1606