in reply to file input problem

#!/usr/bin/perl use CGI::Cookie; print "Content-type:text/html\n"; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } $log = $FORM{username}; $pass = $FORM{password}; open (FILE, "users"); while(<FILE>){ $fl = <FILE>; chomp $fl; ($name, $value) = split(/,/, $fl); $refpass = $value; $reflog = $name; close FILE; if ($pass eq $refpass && $log eq $reflog) { print "Set-Cookie: usernamefromzybak=$refpass\n\n"; print <<EndHTML; <html><head><title>testing</title></head> <body> welcome , $FORM{username} <br /> to 171:4's headquarters!<br /> <a href="hq.cgi">Enter now!</a> </body></html> EndHTML close FILE; } } close FILE;
This is the latest update I have done... it may be working, or I may have been in the middle of something... but this is the entire script.

Thanks to those that have answered

Replies are listed 'Best First'.
Re: Re: file input problem
by merlyn (Sage) on Apr 25, 2001 at 20:00 UTC
Re: Re: file input problem
by thabenksta (Pilgrim) on Apr 25, 2001 at 20:20 UTC

    The reason you are getting 500 error is becuase you are not printing anything out if the username and password don't match. You need to do an else statement after the if ($pass eq $refpass && $log eq $reflog) that prints out invalid login or something, to account for failed logins.

    -thabenksta
    my $name = 'Ben Kittrell'; $name=~s/^(.+)\s(.).+$/\L$1$2/g; my $nick = 'tha' . $name . 'sta';
      THANK YOU thabenksta!!!!

      although I can't use the else the way the script is now, you were 100% right... no more 500's...

      I have taken some of the other suggestions to heart as well... so thanks to everyone who replied!!!

      now if I knew how to delete the question...
Re: Re: file input problem
by coolmichael (Deacon) on Apr 26, 2001 at 05:04 UTC
    I don't mean to critisize your code, especially when you haven't asked for this type of comment, but CGI.pm will handle all the parameters for you, so you don't need all the stuff on line five to fourteen. You could even change them to $log=param('username');$pass=param('password');

    It will also generate all the HTML for you. Ovid has an excellent tutorial linked to on his home node that has helped me with CGI a great deal, and talks about why you shouldn't try get the parameters the way you have. He also wrote use CGI or Die;.

    Actually, merlyn beat me to it.

    michael
    the blue haired monk

Re: Re: file input problem
by Anonymous Monk on Apr 25, 2001 at 20:12 UTC
    Yer?

    uh, the open part of it I was tinkering with, it was always what I had at the top, I changed it to try and avoid the 500's... but it just worked less... :-(

    as for CGI.pm, I wanted to get it working before I tried that, but if you guys think it'd help, I can give it a go...
      well even if the file doesnt exist and you have -w and use strict set you still will not get a 500 error. for example
      #!/usr/local/bin/perl -w use strict; use CGI; my $q = new CGI; print $q->header, # create the HTTP header $q->start_html('Whatever'), # start the HTML open(FILE, "data.txt") while(<FILE>){ chomp; print "Saw $_ in data.txt<br>\n"; } close FILE; print $q->end_html;
      Will produce :
      Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>W +hatever</title> Use of uninitialized value in print at ./test.pl line 8. readline() on closed filehandle main::FILE at ./test.pl line 12. </head><body></body></html>
      if data.txt doesn't exist, which most browsers+servers will handle ok....
      Of course I'm not saying you should do it like this :-) D