You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jason Wilkes <se...@yahoo.co.uk> on 2002/07/04 17:46:14 UTC

Understanding why this "fixes" my perlaccess script

Hi folks,

I use the following modperl script to control page
access, based on a sessionid held in a cookie. A
database is queried to get the user id from the db
based on the cookie value. (No cookie, and your
bounced to the logon screen).

So far so good, and all works well. Except for one
user id (actually id=333), which causes an "internal
server error". If I put print debugging lines in -
everything works (even for user 333). If I take them
out again all other users work fine except 333.
Can anybody throw any light on this??

BTW: when the "internal server error" happens there is
no log of it in the error_log - although the HTTP
response code in access_log is 333 (which I don't
think is a valid response code).

Any thoughts would be much appreciated.

The code is: -

package My::Package;

use strict;
use Apache::Constants qw(:common);
use CGI::Cookie;
use DBI;

sub handler {

open (DBG, ">>/tmp/debug.txt"); # DEBUG LINE

my $r = shift;
my %cookies =
CGI::Cookie->parse($r->header_in('Cookie'));
return (FORBIDDEN) unless $cookies{'SessionID'};

my $SessionID = $cookies{'SessionID'}->value;

...
stuff to set up the DBI connection
...

        my $sth = $dbh->prepare("
                SELECT id from session
                WHERE field = '$SessionID'
                ");
        $sth->execute;
        my $answer = $sth->fetchrow;

print DBG "The id is $answer\n"; # DEBUG LINE

        $sth->finish;
        $dbh->disconnect;

        return (FORBIDDEN) unless $answer;
        
close (DBG);

}

1;
__END__







__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Re: Understanding why this "fixes" my perlaccess script

Posted by Perrin Harkins <pe...@elem.com>.
Jason Wilkes wrote:
> So far so good, and all works well. Except for one
> user id (actually id=333), which causes an "internal
> server error". If I put print debugging lines in -
> everything works (even for user 333). If I take them
> out again all other users work fine except 333.
> Can anybody throw any light on this??

Yes.  You are returning the value of the last operation, 333, when 
$answer is not true.  To fix it, you should return DECLINED (or OK if no 
other access handlers should be allowed to run).

Why does it work when you debug?  Because you change the value of the 
last operation.

> BTW: when the "internal server error" happens there is
> no log of it in the error_log - although the HTTP
> response code in access_log is 333 (which I don't
> think is a valid response code).

There is no server error.  Your browser is just interpreting the 
response of 333 as a sign that something went wrong and putting a pretty 
face on it.  Microsoft browsers are notorious for this, although you can 
turn the behavior off.

- Perrin