Dear fellow monks,

I played a little with mod_perl and Apache::Session this afternoon, and, just for fun, decided to create kind of a forum, where everyone can read, but only authenticated users can write messages.

Mod_perl is a tricky thing, especially concerning global vars, so I put most of my code into a module and use it. The first quick and dirty steps were all successful, I could connect to the database, print out the messages and so on. But when I wanted to implement the authentication functions, I got stuck.
Well, here's my code:
# this is index.pl use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use strict; use Perlnews; my $q = new CGI; my $n = new Perlnews; $n->html_head(); if ($q->param("op") eq "login") { $n->auth($q->param("login"), $q->param("password")); $n->main_page(); } else { $n->main_page(); } $n->html_foot(); ---------- # And this is a part of the module I wrote ### Apache Session thingies my $request = Apache->request; my $cookie = $request->header_in('Cookie'); $cookie =~ s/PN_SESSION_ID=(\w*)/$1/; my %session; tie %session, 'Apache::Session::MySQL', $cookie, { Handle => $dbh, Loc +kHandle => $dbh }; my $session_cookie = "PN_SESSION_ID=$session{_session_id};"; $request->header_out("Set-Cookie" => $session_cookie); ## Authentication subroutine sub auth { my ($login, $passwd) = @_; $sth = $dbh->prepare("SELECT id, login FROM users WHERE login = ? +AND passwd = ENCRYPT(?, passwd)"); $sth->execute($login, $passwd); if ($sth->rows != 1) { $error = "Oops, the was something wrong with your login or pas +sword!"; } else { my $r = $sth->fetchrow_arrayref(); $session{userid} = $r->[0]; $session{login} = $r->[1]; } $sth->finish; }
Without having the if-else clause, everything went fine, it just printed out the main page. But after putting in the Session and auth stuff, I sometimes get the page, but mostly the server seems to hang in an endless loop... Netscapes comets keep moving, but there's no response. There seems to be nothing wrong on the server, system load and process list show nothing unusual. I guess it has to do with table locking, but actually I didn't even try to enter a login and passwd, I just hit Reload. Any ideas?

In reply to mod_perl, Apache::Session by le

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.