# 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, LockHandle => $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 password!"; } else { my $r = $sth->fetchrow_arrayref(); $session{userid} = $r->[0]; $session{login} = $r->[1]; } $sth->finish; }