Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Good way to redirect to a "members only" section of website

by ww (Bishop)
on Feb 02, 2013 at 19:33 UTC ( #1016741=note: print w/ replies, xml ) Need Help??


in reply to Good way to redirect to a "members only" section of website

... 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: &nbsp; <input type="text" id="ckin" name="ckin" size="15"> </label> &nbsp; <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> &nbsp; </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.


Comment on Re: Good way to redirect to a "members only" section of website
Select or Download Code
Re^2: Good way to redirect to a "members only" section of website
by yagna (Novice) on Feb 02, 2013 at 22:46 UTC
    Hi ww, Thanks for the code snippet. This works for me. Thanks again! Yagna

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016741]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-08-01 02:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls