vcherubini
Programmer
Hello. I wrote the following script in order to allow people to enter a forum, like this one, with a user name and password.<br><br><FONT FACE=monospace><br><br>#!usr/bin/perl -w<br><br># location of the txt file <br>$datadir = "e:\\virtualhosts\\epicsoftware.com\\ collect the data from the user using Post<br><br>read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});<br>@pairs = split(/&/, $buffer);<br>foreach $pair (@pairs) {<br> ($name, $value) = split(/=/, $pair);<br> $value =~ tr/+/ /;<br> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;<br> $FORM{$name} = $value;<br>}<br><br>if ($FORM{'action'} eq "checkpassword"
{ &checkpassword; }<br>else { &default; }<br><br>sub default {<br>print "Content-type: text/html\n\n";<br>print "<html>\n<head>\n<title>Enter your user name and Password</title>\n</head>\n";<br>print "<body>\n";<br>print "<form method=\"post\">\n";<br>print "<input type=\"hidden\" value=\"checkpassword\" name=\"action\">\n";<br>print "<font face=\"verdana\" size=\"-2\" color=\"black\"><b>username:</b></font>\n";<br>print "<br><input type=\"text\" name=\"user\" style=\"background:00648E; color:white; height:20; font-size:10px;\"><br>\n";<br>print "<font face=verdana size=-2 color=black><b>password:</b></font>\n";<br>print "<br><input type=\"password\" name=\"password\" style=\"background:00648E; color:white; height:20; font-size:10px;\"><br>\n";<br>print "<input type=\"submit\" value=\"Enter\" style=\"background:black; color:white; height:20; font-size:10px;\">\n";<br>print "<input type=\"Reset\" value=\"Clear\" style=\"background:black; color:white; height:20; font-size:10px;\">\n";<br>print "</form>\n";<br>print "</body>\n</html>\n";<br>}<br>sub checkpassword {<br><br>open(FILE, "$datadir/data.txt"
¦¦ die("File does not reside on server: $!"
;<br><br>while (<FILE>
{<br><br>@data = split(/\n/);<br>foreach $entry (@data) {<br><br>($user, $password) = split(/,/, $entry);<br><br>if ($name eq "$user"
{<br><br>$userverified = "1";<br>}<br> if ($password eq "$password"
{<br> <br> $passwordverified = "1";<br> <br> <br> }<br> }<br> }<br> close(FILE);<br> <br> if ($userverified && $passwordverified) {<br> <br>&accessgranted;<br><br>} elsif ($userverified) {<br><br>&badpassword;<br><br>} else {<br><br>&baduserpass;<br><br>}<br>}<br><br>sub accessgranted {<br><br>print "<html><head><title>access granted</title></head>\n";<br>print "<body>\n";<br>print "<h1>access granted</h1>\n";<br>print "</body>\n";<br>print "</html>\n";<br><br>}<br><br>sub badpassword {<br><br>print "<html><head><title>bad password</title></head>\n";<br>print "<body>\n";<br>print "<h1>bad password</h1>\n";<br>print "</body>\n";<br>print "</html>\n";<br><br>}<br><br>sub baduserpass {<br><br>print "<html><head><title>bad username and password</title></head>\n";<br>print "<body>\n";<br>print "<h1>bad username and password</h1>\n";<br>print "</body>\n";<br>print "</html>\n";<br><br>}<br><br><br></font><br><br>When I upload and run the script, I get the following error:<br><br><FONT FACE=monospace><br><br>CGI Error<br>The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:<br><br><br>Name "main:
ass" used only once: possible typo at e:\virtualhosts\epicsoftware.com\ line 45.<br>Name "main::user" used only once: possible typo at e:\virtualhosts\epicsoftware.com\ line 47.<br>Use of uninitialized value at e:\virtualhosts\epicsoftware.com\ line 9.<br>Use of uninitialized value at e:\virtualhosts\epicsoftware.com\ line 47, chunk 1.<br>Use of uninitialized value at e:\virtualhosts\epicsoftware.com\ line 51, chunk 1.<br>Use of uninitialized value at e:\virtualhosts\epicsoftware.com\ line 51, chunk 1.<br>Use of uninitialized value at e:\virtualhosts\epicsoftware.com\ line 47, chunk 2.<br>Use of uninitialized value at e:\virtualhosts\epicsoftware.com\ have never gotten an error like this one before. Any help on decoding the error and my code will be greatly appreciated.<br><br>Thanks.<br><br>Vic