in reply to Checking for "return undef"

You need to look at your cascade of if-else's:
if ( $cookies->{license_session} ) { ... if ( defined $s ) { ... } } else { # set cookie ... }
when running through this code, when checking $cookies->{license_session}
if true, you drop into the code block for that if, otherwise you do the cooresponding else.

So lets say you get into the if, and the $s is not defined. There is no cooresponding else with the if that checks if $s is defined.
The else that causes the redirect is matched with the outer if.

Replies are listed 'Best First'.
Re: Re: Checking for "return undef"
by neilwatson (Priest) on Apr 21, 2004 at 16:25 UTC
    I see your point. I fixed the if structures, but the problem persists:
    use strict; use warnings; use lib "/usr/local/apache/virtual/itiv/modules"; use Mapps::Session; use Mapps::Auth; #################### # Get current session # and check for expiry my $sid; # get session id from cookie my $cookies = Apache::Cookie->fetch(); if ($cookies->{license_session}) { $sid = $cookies->{license_session}->value(); # load session from db my $s = Mapps::Session->new(); $s->load_session($sid); # session is good continue if (defined $s){ $m->call_next; # Else session is undefined }else{ denied(); } # Else cookie does not exist. }else{ denied(); } # Delete cookie and # redirect to login. sub denied { # set cookie Apache::Cookie->new( $r, name => 'license_session', value => '', path => '/', )->bake; my $url = $m->comp('/login.html', msg=>"Invalid session or cookie" +); print "$url\n\n"; }

    Neil Watson
    watson-wilson.ca