Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Here is my try at an example

#!/usr/bin/perl use strict; use warnings; select STDOUT; $| = 1; my $session_dir='/home/huck/monks-sessions'; # must exist and be wr +iteable by www userid my $expires='+1m'; # '+7d' '+1h' ; my $cookieexpires=$expires; use CGI; use CGI::Session; use CGI::Cookie; my $session; my $notloggedin=''; my $cookies; my %passwords=(admin=>'admin',huck=>'huck'); my $cgi = CGI->new; my $tssid = $cgi->cookie('TSSID'); my $timelast; unless ($tssid){ my $userid =$cgi->param('userid'); my $password=$cgi->param('password'); $userid='' unless ($userid); $password='' unless ($password); unless ( $userid) {$notloggedin='Ple +ase Login';} elsif (! $passwords{$userid}) {$notloggedin='Bad + Userid';} elsif ($password ne $passwords{$userid}) {$notloggedin='Bad + Password';} else { $session = CGI::Session->new(undef, undef, {Directory=>$sess +ion_dir}); $cookies = [CGI::Cookie->new(-name => 'TSSID', -value => $session->id, -expires => $cookieexpires )]; $session->expires($expires); $session->param('user_id',$userid); $session->param('timein' , time); $session->param('timelast', time); $timelast=time; $session->flush(); } # ok } # no tssid else { $session = CGI::Session->load(undef, $tssid, {Directory=>$sessio +n_dir}); if ( $session->is_expired ) { $notloggedin='login expired ' ; $session->delete(); $session->flush(); } elsif ( $session->is_empty ) { $notloggedin='login not found'; +} else { $cookies = [CGI::Cookie->new(-name => 'TSSID', -value => $session->id, -expires => $cookieexpires )]; $timelast=$session->param('timelast'); $session->param('timelast', time); $session->flush(); } } if ($notloggedin){ $cookies = [$cgi->cookie(TSSID => '')]; print $cgi->header(-cookie=>$cookies); print '<html><head><title>Must login</title></head><body>'."\n"; + print '<h1>Must login</h1>'."\n"; print '<h3>'.$notloggedin.'</h3>'."\n"; print '<form method="POST">'."\n"; print 'Userid:<input type="text" name="userid">'."\n"; print ' Password:<input type="text" name="password">'."\n"; print '<input type="submit" value="Login">'."\n"; print '</form>'."\n"; } else { if ($cookies) {print $cgi->header(-cookie=>$cookies); } else { print $cgi->header(); } print '#html content after seccessfully login'; print '<br>hi '.$session->param('user_id'); print ' loggedin for '.(time-$session->param('timein')).' second +s'; print ' last seen '.(time-$timelast).' seconds ago'; } print '</body></html>'; CGI::Session->find(undef ,sub {} ,{Directory=>$session_dir}); # clea +n expired sessions


In reply to Re^2: basic login by huck
in thread basic login by bigup401

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-03-28 18:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found