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);
}
--
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/