... and the layout here ain't exactly wonderful but, anyway, here's a snippet from an "index.html" (default) page:
<form action="../cgi-bin/login.cgi" name="checkin" id="checkin" method
+="post">
<label for="ckin">Account ID:
<input type="text" id="ckin" name="ckin" size="15">
</label>
<input name="Submit" type="submit" value="Ordering">
</form>
The 'action' element of the form specifies the file to be used for checking the input, <Aside: which, in this case, is solely an account ID (all alphas) because the site owner estimates his risks are minimal (for reasons beyond the scope of this discussion) despite using a single-element login). /Aside>
The called script ("login.cgi") is an antique, but works more or less like this:
#!/usr/bin/perl -wT # read about Tainted input or die
use strict;
use CGI qw(:standard escapeHTML);
use vars qw ( @accts $acct_name $all_accts );
our $value = (param('ckin')); # get account ID from the form above
unless ( $value =~ /^[a-z]{5}$/i )
{
&out_badlog(); # See *1
exit;
}
# See *2
open (INFILE,'<', 'accts.db') or die "Can't open accounts data";
our ( @accts ) = split /\s/,<INFILE>;
close (INFILE);
for $acct_name( @accts )
{
$all_accts = $all_accts . $acct_name;
}
if ( $all_accts =~ /$value/ )
{
&out_logged_in($value); # See *3
} else {
&out_badlog($value);
}
...
# BAD LOGIN PAGE - output a doc
sub out_badlog {
print <<_END_OF_INPUT_
<html lang="en">
<head>
<title>Sample title</title>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="description" content="...">
<meta name="keywords" content="...">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" type="text/css" href="../foo.css">
</head>
<body>
... banner, other foofarawh here....
<h1 style="margin-left: 3em;">Bad login!</h1>
_END_OF_INPUT_
;
print ('<h2 style="margin-left: 4em;">Login attempted was: ' . $value
+. '</h2>');
print <<_END_OF_VAL
<h3 style="margin-left: 8em;">That was NOT a valid login!</h3>
<p> </p>
<p style="margin-left: 16em;"><a href="../index.html">Back to login pa
+ge</a></p>
<br>
</body>
</html>
_END_OF_VAL
;
}
...and, similarly for the good log-in sub...
Hope this helps... (and does not suggest too many obsolete or bad practices)
*1 This sub could redirect to page2.html or could (using a heredoc, for instance) produce the hmtl for page2.htm and feed it to the user's browser.
*2 'accts.db' holds a single (long!) string of all valid accounts.
*3 The sub 'out_logged_in()' produces renderable .html -- which, for ex., could be the source of your "application_page1.cgi" -- but which, in this case, uses a heredoc to create a page allowing the successfully-logged-in-user to continue to a variety of applications pages.
You can do this a good many different ways and careful scrutiny will tell you it's not exactly in accord with my currently preferred schema, but it is, I think, easily enough understood and adapted. You'll find better ways as you grow in your Perl-fu.
Update: Edited out an irrelevant <style=...> to further reduce the width of the code and fixed the closing "Aside" pseudotag. IOW, no substantive change.
-
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.