there's a login page, which checks that a user is registered in our member database, and, if so, sets a session id cookie in SESSID, as well as a userid in TIUID. SESSID is generated using:
my $sessid = join("", @chars[ map { rand @chars } (1 .. 20) ]);
then, every page that is password-protected has the following at the top:
my $q = new CGI; my $sessid = $q->cookie('SESSID'); my $UIDuser = $q->cookie('TIUID'); my %in = map { $_ => $q->param($_) } $q->param; if (!$sessid) { print $q->redirect("http://mydomain.org/memberarea/login/"); exit; } my $cookie = $q->cookie(-name=>"SESSID", -value=> $sessid, -expires => + "+2h", -domain=> '.mydomain.org'); print $q->header({-type=>"text/html", -charset=>"utf-8", -cookie=>$coo +kie}); my $pagetitle; my $dbh = DBI->connect('DBI:mysql:sitedatabase;host=localhost;port=330 +6', 'ouradminname', 'oursecretpassword') or die "Couldn't open database: $DBI::errstr; stopped"; my $sql = "SELECT UID, firstname, lastname, role FROM members WHERE lo +ginkey = '$sessid'"; # Prepare the SQL query for execution my $sth = $dbh->prepare($sql) || die "Couldn't prepare statement: $DBI::errstr; stopped"; # Execute the query my $result = $sth->execute || die "Error executing: $DBI::errstr"; if ($result == 0) { print $q->redirect("http://mydomain.org/memberarea/login/"); exit; }
anyone with an expired or non-existent SESSID is redirected to the login page.

In reply to Re^2: Protecting a PDF file by jck
in thread Protecting a PDF file by jck

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.