This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.
Subject: Browser Sniffing From: Drew Taylor <dtaylor@vialogix.com> Date: Thu, 29 Jun 2000 14:57:27 -0400 I am about to embark on a journey to find/create a brower sniffing module. It should get three things: 1) Browser 2) Version 3) Platform. Has anyone created such a beast? If I write it myself, I will be happy to share the code with those on the list. I'm hoping it's been done already, because the user-agent strings are terribly inconsistent... === Subject: Re: Browser Sniffing From: Casey Bristow <Casey.Bristow@xor.com> Date: Thu, 29 Jun 2000 13:30:15 -0600 (MDT) I've also played with the idea of creating a similiar class, but have not had time to really get on with it.. The best client sniffer that I have found thus far is a javascript (ewww) one.. but it would rock to have this functionality as an apache mod! http://developer.netscape.com:80/docs/examples/javascript/browser_type.html I'm more than willing to help with this if you so desire.. just haven't gotten around to it myself yet. === Subject: Re: Browser Sniffing From: Drew Taylor <dtaylor@vialogix.com> Date: Thu, 29 Jun 2000 15:43:47 -0400 Casey Bristow wrote: > > I've also played with the idea of creating a similiar class, but have not > had time to really get on with it.. The best client sniffer that I have > found thus far is a javascript (ewww) one.. but it would rock to have this > functionality as an apache mod > > http://developer.netscape.com:80/docs/examples/javascript/browser_type.html Thanks for the link. It will be most useful as I improve the sniffing code. Here is the code I have thus far. It seems to work with IE 4+ on Mac & windoze, NS 3+ on Mac & Windoze, and it recognizes my linux Netscape as unix :-). It is very simplistic, but I guess something is better than nothing. sub BrowserPlatform { my $self = shift; my $agent = shift || $self->{R}->headers_in->get('User-Agent'); $agent = lc($agent); my ($platform, $browser, $version) = ('','',0); # browser version if ( $agent =~ /msie (\d)/ ) { $version = int($1); } elsif ($agent =~ m#^mozilla/(\d)#) { $version = int($1) } else { $version = 3; } # check browser if ( $agent =~ /mozilla/ && $agent !~ /msie/ ) { $browser = 'netscape'; } elsif ( $agent =~ /msie/ ) { $browser = 'msie'; } else { $browser = 'other'; } # check platform if ( $agent =~ /mac/ or $agent =~ /ppc/ or $agent =~ /powerpc/) { $platform = 'mac'; } elsif ( $agent =~ /win/ ) { $platform = 'win'; } elsif ($agent =~ /linux/ or $agent =~ /sunos/) { $platform = 'unix'; } else { $platform = 'other'; } print STDERR "BrowserPlatform: Browser=$browser Platform=$platform Version=$version\n" if $DEBUG; return ($browser, $platform, $version); } === Subject: Re: Browser Sniffing From: Ask Bjoern Hansen <ask@valueclick.com> Date: Thu, 29 Jun 2000 13:14:34 -0700 (PDT) On Thu, 29 Jun 2000, Drew Taylor wrote: > I'm hoping it's been done already, because the user-agent strings are > terribly inconsistent... I needed something like that once and ended up with this: sub UA { my $ua = shift; my $n = ""; my $v = ""; # $n is the name of the browser # $v the version $ $p the platform # $ua the full useragent string # grap the beginning of the UA string for the name ($n) = ($ua =~ m/^([^\/]+)\//); # but everything calls itself Mozilla, so let's check for a few more # known browsers $n = "msie" if m/MSIE/; # it's worse, these babies calls themself both MSIE and Mozilla, doh! $n = "webtv" if m/webtv/i; $n = "opera" if m/opera/i; # try getting the version ($v) = ($ua =~ m/\/((\d+)(\.\d+)?)/)[0]; # loosen up what we match on a little and try again if we didn't get # a match ($v) = ($ua =~ m/((\d+)(\.\d+)?)/)[0] unless $v; # these thingies call themself Mozilla/N.Z, so let's get their real # version number ($v) = (m/MSIE ((\d+)(\.\d+)?)/) if ($n eq "msie"); ($v) = (m/webtv\/((\d+)(\.\d+)?)/i) if ($n eq "webtv"); ($v) = (m/opera[\s\/]((\d+)(\.\d+)?)/i) if ($n eq "opera"); # guess the platform my $p = ""; $p = "w" if $ua =~ m/win/i; $p = "w16" if $ua =~ m/win(dows)?\s?3\.1/i; $p = "w16" if $ua =~ m/win.*16(bit)?/i; $p = "w95" if $ua =~ m/win(dows)?\s?95/i; $p = "w98" if $ua =~ m/win(dows)?\s?98/i; $p = "wnt" if $ua =~ m/win(dows)?\s?NT/i; $p = "w32" if $ua =~ m/win(dows)?\s?32/i; $p = "x11" if $ua =~ m/X11/; $p = "mac" if $ua =~ m/mac/i; $p = "os2" if $ua =~ m/os\/2/i; $p = "webtv" if $n eq "webtv"; $n = lc($n); die "No name for $ua?\n" unless $n; #return $n, $v, $p; return "$n-$v-$p"; } === Subject: Re: Browser Sniffing From: Drew Taylor <dtaylor@vialogix.com> Date: Thu, 29 Jun 2000 16:35:51 -0400 Ask Bjoern Hansen wrote: > > On Thu, 29 Jun 2000, Drew Taylor wrote: > > > I'm hoping it's been done already, because the user-agent strings are > > terribly inconsistent... > > I needed something like that once and ended up with this: <snip> Cool! I ripped off the browser & version code. It seemed much more conprehensive than mine. :-) Next question, what if this was turned into a proper Apache module and run as the PerlFixupHandler. It could put the sniffer results into $r->notes entries, which could then be used where ever needed. I'll assume it would just return DECLINED so the standard handlers will be run. Does this sound like a useful project? I think I could probably squeeze it in within a few days, using Ask's and my code. === Subject: Re: Browser Sniffing From: Gunther Birznieks <gunther@extropia.com> Date: Fri, 30 Jun 2000 08:29:10 +0800 Would you mind please submitting this as a standard NON-Apache CPAN module? There are too many modules (even 1 is too many... ;)) under the Apache::* moniker that actually can be used in generic CGI programs. The fixuphandler sounds interesting, but I would prefer if that were a wrapper around another module that generically is designed to check the user agent regardless of mod_perl, PerlEx, Win32Perl, CGI/Perl. FastCGI, whatever... So two CPAN submissions, one under Apache::* and another under CGI::* or maybe under LWP.... (I prefer CGI::* though)... === Subject: Re: Browser Sniffing From: Gunther Birznieks <gunther@extropia.com> Date: Fri, 30 Jun 2000 10:18:28 +0800 At 09:06 AM 6/30/00 +0700, Edwin Pratomo wrote: >Ask Bjoern Hansen wrote: > > > > On Thu, 29 Jun 2000, Drew Taylor wrote: > > > > > I'm hoping it's been done already, because the user-agent strings are > > > terribly inconsistent... > > > > I needed something like that once and ended up with this: > > > > sub UA { > > my $ua = shift; > > my $n = ""; > > my $v = ""; >.... > >this doesn't seem to be aware of either WAP browsers or the emulators. >A typical usage of this is to return WML pages if the request comes from >a WAP browser, otherwise return html pages. > >Regards, >Edwin. That is a different method. The fact is that you can't really easily tell if a browser is WAP or not from the useragent because there are new ones coming out every day... every phone and potentially every gateway is a user agent (the gateway may add its own details since it is the client that is actually going to the web server). It is part of the HTTP standard to negotiate content. So if a WAP browser can't digest HTML, then text/html will not be among the content types that it accepts I suspect. I would be interested if anyone else has checked this out. I tend to just check a use_wap=on variable in our latest scripts and turn on WML generation for that. Although I know it's a kludge, I haven't really minded because I figure every WML site will end up having an index.wml file as a frontpage which will navigate the user to the full cgi-bin URL. The reality is that no user in their right mind would ever type in a full cgi-bin URL on one of those silly WAP phones. I have one and I got carpal tunnel typing www.extropia.com/cgi-bin/DemoStuff/WebCalendar...bla bla bla ===