Re: Browser Sniffing

2000-06-30 Thread Matt Sergeant

On Fri, 30 Jun 2000, 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.

This is the AxKit WAPChooser media plugin (the UA substrings are taken
from the WAP FAQ which I periodically check and update):

# $Id: WAPCheck.pm,v 1.2 2000/05/02 10:32:07 matt Exp $

package Apache::AxKit::MediaChooser::WAPCheck;

use strict;
use Apache::Constants;

sub handler {
my $r = shift;
my $type;

local $^W;

if ($ENV{HTTP_ACCEPT} =~ /vnd.wap.wml/i) {
$r-notes('preferred_media', 'handheld');
}
elsif (substr($ENV{HTTP_USER_AGENT},0,4) =~ 
/(
Noki
| Eric
| WapI
| MC21 # cough spit hack ;-) (I used to work at
Ericsson)
| AUR\s
| R380
| UP.B
| WinW
| UPG1
| upsi
| QWAP
| Jigs
| Java
| Alca
| MITS
| MOT-
| My\sS
| WAPJ
| fetc
| ALAV
| Wapa
)/x) {
#   warn "set media to handheld!\n";
$r-notes('preferred_media', 'handheld');
}

return OK;
}

1;

-- 
Matt/

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org




RE: Browser Sniffing

2000-06-30 Thread Leon Brocard

Drew wrote:

 I am about to embark on a journey to find/create a brower sniffing
 module.

You may want to have a look at:

http://search.cpan.org/search?dist=HTTP-BrowserDetect
http://www.jamespo.ukshells.co.uk/perl/

Leon "mustn'treinventwheel"
--
Leon Brocard   |   perl "programmer"   |   [EMAIL PROTECTED]





RE: Browser Sniffing

2000-06-30 Thread Geoffrey Young



 -Original Message-
 From: Edwin Pratomo [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, June 29, 2000 10:06 PM
 To: [EMAIL PROTECTED]
 Subject: Re: Browser Sniffing
 
 
 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.

Palm VII is reported to return Mozilla/2.0 (compatible; Elaine/1.0) 
for what it's worth...

--Geoff

 
 Regards,
 Edwin..
 



Re: Browser Sniffing

2000-06-30 Thread Drew Taylor

Leon Brocard wrote:
 
 Drew wrote:
 
  I am about to embark on a journey to find/create a brower sniffing
  module.
 
 You may want to have a look at:
 
 http://search.cpan.org/search?dist=HTTP-BrowserDetect
 http://www.jamespo.ukshells.co.uk/perl/
Ahhh, guess I should have searched CPAN a little. ;-) Thanks for the
links. HTTP-BrowserDetect looks especially useful.

-- 
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/



Re: Browser Sniffing

2000-06-30 Thread Drew Taylor

Gunther Birznieks wrote:
 
 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)...
Well, there is already HTTP::BrowserDetect as someone else pointed out.
It has much more functionality than what I have written. So the only
question left is would an Apache Module which puts
browser/version/platform into the notes table be useful? Should I put
out an RFP on the list? I wrote a quick  dirty PerlFixupHandler which
I'm currently using (and it works :-). Would anyone be interested in the
code?

-- 
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/



Re: Browser Sniffing

2000-06-30 Thread struan

* at 30/06 10:18 +0800 Gunther Birznieks said:
 
 At 09:06 AM 6/30/00 +0700, Edwin Pratomo wrote:
 
 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.

We've had some success by using the HTTP_ACCEPT header and plain old
apache redirects for WAP. We did try UA sniffing but as you say the
sheer number of new browsers coming out meant we were changing stuff
almost daily.

Struan
-- 
Struan Donald
mailto:[EMAIL PROTECTED]
Code Flunky, 365 Plc.
http://www.365corp.com/



Re: Browser Sniffing

2000-06-29 Thread Casey Bristow


 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.

On Thu, 29 Jun 2000, Drew Taylor wrote:

 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...
 
 

-- 

 -Casey






Re: Browser Sniffing

2000-06-29 Thread Drew Taylor

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/



Re: Browser Sniffing

2000-06-29 Thread Ask Bjoern Hansen

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";
}


-- 
ask bjoern hansen - http://www.netcetera.dk/~ask/
more than 70M impressions per day, http://valueclick.com





Re: Browser Sniffing

2000-06-29 Thread Drew Taylor

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.

-- 
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/



Re: Browser Sniffing

2000-06-29 Thread Gunther Birznieks

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)...

Later,
Gunther "Module Naming Nazi" Birznieks

At 04:35 PM 6/29/00 -0400, Drew Taylor 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:
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.

--
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/

__
Gunther Birznieks ([EMAIL PROTECTED])
eXtropia - The Web Technology Company
http://www.extropia.com/




Re: Browser Sniffing

2000-06-29 Thread Scott Alexander

Looking at this,  I'm tempted to do a similar thing.  My thought was 
to take the code and then twist it slightly to put the information into 
a database.  ie when I create a new session,  grab the information 
about browser etc.

Would save me a bit if it were already a completed apache:: 
module but if not.  I'll do it probably within the next three weeks.

Scott
On 29 Jun 2000, at 16:35, Drew Taylor wrote:
 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.





Re: Browser Sniffing

2000-06-29 Thread brian moseley

On Fri, 30 Jun 2000, Gunther Birznieks wrote:

 There are too many modules (even 1 is too many... ;))
 under the Apache::* moniker that actually can be used in
 generic CGI programs.

yeah, i'm thinking the same thing about Apache::Session!




Re: Browser Sniffing

2000-06-29 Thread brian moseley

On Fri, 30 Jun 2000, Gunther Birznieks wrote:

 So two CPAN submissions, one under Apache::* and another
 under CGI::* or maybe under LWP (I prefer CGI::*
 though)...

i vote HTTP!




Re: Browser Sniffing

2000-06-29 Thread Edwin Pratomo

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.



Re: Browser Sniffing

2000-06-29 Thread Gunther Birznieks


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

Later,
Gunther

__
Gunther Birznieks ([EMAIL PROTECTED])
eXtropia - The Web Technology Company
http://www.extropia.com/