in reply to Need help protecting the user - detecting and redirecting browsers the ADVANCED way...

i would suggest inverting your logic to use three hashes, my (%passed, %failed, %untested); (i'm not sure you need a fourth). once you get the browser type, test for existence of the key in the three hashes. if it doesn't exist in the third, add the key, then redirect. a lengthier example might look like:

my (%passed, %failed, %untested); %passed = { MSIE50NT => 1, MSIE55NT => 1, URI_REDIRECT => 'http://passaddress/', }; # set %failed and %untested my $br_detect = 'palm'; # as found by HTTP::BrowserDetect if( defined $passed{$br_detect} ) { redirect( $passed{URI_REDIRECT} ) +} if( defined $failed{$br_detect} ) { redirect( $failed{URI_REDIRECT} ) +} defined $untested{$br_detect} ? '' : %untested{$br_detect} = 1; redirect( $untested{URI_REDIRECT} ); sub redirect { # your redirect logic here... }

~Particle ;Þ

  • Comment on Re: Need help protecting the user - detecting and redirecting browsers the ADVANCED way...
  • Select or Download Code

Replies are listed 'Best First'.
Re: Re: Need help protecting the user - detecting and redirecting browsers the ADVANCED way...
by S_Shrum (Pilgrim) on Mar 02, 2002 at 04:05 UTC

    Say a user attempts to view a page and the browser is detected to have not passed. I would like to be able to list (for ( keys %passed )) the passed browsers along with formal browser names, versions, and URL info.

    I am seeing something like this forming:

    my %passed = { # MSIE 5.0 on MS NT 4.0 1 = ( HTTP_USER_AGENT => "Mozil +la/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)", NAME => "MS Internet + Explorer" VERSION => "5.0" PLATFORM => "NT" MANUFACTURER => "Microsoft" URL => "http://w +ww.microsoft.com"

    Does this seem like the correct way to go with this idea? How would I structure the line to display the info like:

    Here is a list of browsers that have passed testing:
    
       + MS Internet Explorer 5.0 / NT (http://www.microsoft.com)
    ...

    being that the info is a hash in a hash in a hash?

    ======================
    Sean Shrum
    http://www.shrum.net

      since you're building this data structure manually, you have the ability to keep it in a config file, and do or eval it when neccessary. if you have unique values, for instance HTTP_USER_AGENT, you can use this as the key to the hash. i have an example below.

      if you don't have unique values, or require some combination of values for a unique key, you'll have to modify the data structure a little bit, to make sure your keys are unique.

      in any case, a read through perldsc will give you insight on working with complex data structures like hashes of hashes.

      my %passed = { "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"=> { NAME => "MS Internet Explorer", VERSION => "5.0", PLATFORM => "NT", # more specialized info here }, # more HTTP_USER_AGENT strings here... URI_REDIRECT => 'http://passaddress/', }; # if $test_key is the unique browser identifier you're looking for # you may print like... my $message = join( ' ', $passed{$test_key}->{NAME}, $passed{$test_key}->{VERSION}, '/', $passed{$test_key}->{PLATFORM), # etc. );

      ~Particle ;Þ

        Ahhhh! I didn't know you could have key names with spaces in them. I learned something new. In that case, you're right.

        Moo-Chess-Grass-e-ous!

        ======================
        Sean Shrum
        http://www.shrum.net