CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Registration Script Driving Me Crazy! Please Help!

 



abockover
Deleted

Oct 11, 2000, 4:27 PM

Post #1 of 3 (675 views)
Registration Script Driving Me Crazy! Please Help! Can't Post

I am having a problem with this simple registration script.

With this script, users can sign up for a service on my website.

All it does is make sure fields are not blank, check that you are a certian age, and make sure that the user name the user wants is not already taken.

It works when I execute it from the command line, but not in the browser.

What is going wrong? IT IS DRIVING ME CRAZY!

Please help,
The code is below,

Aaron

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#!/usr/bin/perl

&parse_form;

## Define databases
$userlist = "users.db";
$userdata = "$username";
$allusers = "userdb.db";

## Define fields

$firstname = $input{'firstname'};
$lastname = $input{'lastname'};
$age = $input{'age'};
$email = $input{'email'};
$username = $input{'username'};
$password = $input{'password'};
$confirmpass = $input{'confirmpass'};

if($firstname eq "") {
$error = "Your first name is required to create an account\n";
&showError;
}
if($lastname eq "") {
$error = "Your last name is required to create an account\n";
&showError;
exit;
}
if($age eq "") {
$error = "Your age is required to create an account\n";
&showError;
exit;
}
if($age <=13) {
$error = "You must be over the age of 13 to create an account\n";
&showError;
exit;
}
if($email eq "") {
$error = "Your email address is required to create an account\n";
&showError;
exit;
}
if($username eq "") {
$error = "A username is required to create an account\n";
&showError;
exit;
}
if($password eq "") {
$error = "A password is required to create an account\n";
&showError;
exit;
}
if($password ne "$confirmpass") {
$error = "Passwords do not match required to create an account\n";
&showError;
exit;
}

open (USERS,"<$userlist") or die $!;
while (<USERS> ) {
next unless /^\Q$username|\E/;
$user_exists = 1;
last;
}

if($user_exists) {
$error = "The username <i>$username</i> is already in use by someone else. Choose another username.\n";
&showError;
exit;
} else {

## Add the user to the user database

open(MKUSR,">>users/$userlist");
print MKUSR "$username|CS\n";
close(MKUSR);

## Make the user's settings file

open(USRSET,">users/settings/$username.$password.cfg");
print USRSET "$firstname|$lastname|$age|$email|$username|$password\n";
close(USRSET);

## Add user to database

open(USRDB,">>users/database/$allusers");
print USRDB "$firstname|$lastname|$age|$email|$username|$password\n";
close(USRDB);

print <<"EOF";
<html>
<body>
Thank You
</body>
</html>

EOF
exit;
}


sub showError {

print <<"EOF";
<html>
<body>
An Error has occured: $error
</body>
</html>

EOF


}

sub parse_form {

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}
@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;

$input{$name} = $value;
}
}
</pre><HR></BLOCKQUOTE>


dws
Deleted

Oct 11, 2000, 9:41 PM

Post #2 of 3 (675 views)
Re: Registration Script Driving Me Crazy! Please Help! [In reply to] Can't Post

Add <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">quote:</font><HR>print "Content-type: text/html\r\n\r\n";<HR></BLOCKQUOTE>to the top of the file, then add code to check the return value of open().



abockover
Deleted

Oct 11, 2000, 10:50 PM

Post #3 of 3 (675 views)
Re: Registration Script Driving Me Crazy! Please Help! [In reply to] Can't Post

Oowwwa!!!

Man, I feel stupid...

Well thanks, I was tired last night. I looked at it when I got home, and the first thing I saw that was missing was:

print "Content Type: text/html\n\n";

Thanks again,

Next time I will really look the code over.

Sorry,

Aaron

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives