
abockover
Deleted
Oct 11, 2000, 4:27 PM
Post #1 of 3
(499 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>
|