This is a continuation of the SOPW I made the other day CGI forms (basic). The code below worked wonders when it was called as a CGI to log people in to the script. Originally you would go to script.cgi in the browser and it would give you the login form to sign in with, do all the testing, sign you in if a success, post an error message and repost login form if failed.

It worked perfectly but now instead of having the CGI do everything, I have an HTML form passing data to this CGI and now it's not working. The only difference between this and the original is it doesn't load a form to sign in with in the CGI script unless you type in the wrong information, it requests data form my HTML form instead.

No errors are present but the cookies are NOT setting if they login with the right info. And if the HTML form is submitted emtpy, it prints "test" instead of erroring out and doesn't print the login form.

Do you see what went wrong and what needs to be changed in order to make this take form data from an HTML form and work?

#!/usr/bin/perl use warnings; use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); ####### # collect data from form ####### my $username = param("username"); my $password = param("password"); ######### # Cookie junk ######### my $cookiename = "filemanager"; my $pass= param('pass'); my $tasty = cookie($cookiename); use DB_File; my %users; my $users = "users.db"; # location of database tie %users, "DB_File", "$users", O_CREAT|O_RDWR, 0644 or die "Cannot o +pen file 'default.db': $!\n"; my ($savedpassword, $name, $email, $website, $start) = split(/::/, $us +ers{$username}); ###################################################################### +######################################### # COOKIE CHECKING ###################################################################### +######################################### # First check if we saved a cookie last time if($tasty) { print header(-expires=>'now'), start_html("Link Popularity Checker v1.8 Console"); &processing; print end_html; exit; } ###################################################################### +################################## # Password checking ###################################################################### +################################## unless ($password eq $savedpassword) { print header(-expires=>'now'), start_html("Login"); print <<"FORM"; <table border="2" width="181" bgcolor="#AAAAAA"> <tr> <td bgcolor="#CC0000" valign="bottom"><font color="#FFFFFF" fac +e="Arial, Helvetica, sans-serif">Client Login </font></td> </tr> <tr> <td valign="top"> <table width="181" border="0" align="center"> <form action="/cgi-bin/member/login.cgi" method="post"> <tr> <td width="59">username</td> <td width="122" valign="top"><input name="username" type="t +ext" size="15"></td> </tr> <tr> <td>password</td> <td valign="top"><input name="password" type="password" siz +e="15"></td> </tr> <tr> <td>&nbsp;</td> <td valign="top"><div align="right"> <input type="submit" name="Submit" value="Log In"> </div></td> </tr> </form> </table> FORM if (param()) { my $username = param("username"); my $password = param("password"); if (exists $users{$username}) { my $data = $users{$username}; my ($savedpassword, $name, $email, $website, $start) = split( +/::/, $users{$username}); if ($password ne $savedpassword) { print "<b>Wrong password!</b>"; exit; } } } else { print "username does not exist"; exit; } } ###################################################################### +################################## # Cookie setting ###################################################################### +################################## my $cookie = cookie( -NAME=> $cookiename, -VALUE=> $pass, ); print header(-COOKIE => $cookie, -expires=>'now'); print start_html("Going through here"); &processing; sub processing { print "test"; } ########### END PROCESSING SUB HERE exit;


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

In reply to CGI login issues by sulfericacid

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.