A Simple Script #2

They have: 472 posts

Joined: Oct 1999

I need someone to write a script for me. It's a very simple one.

I intend to provide free email forwards, no ads.

This is how the script should work.

There will be a form first, with 2 fields.
1st one will be the user name for the email address @ my domain. 2nd will the user's real email address.

When the user clicks submit, the script will check a file called email.dat and see if the user name is already taken.
Each user name inside the email.dat file should be placed on each line.

If the user name is already taken, a message that says "User Name already taken, please choose another one." will show up.

If the user name is not taken, the script will bring the user to a "success" page, which can be set by me. And the script will email the results to me.

Then I'll set up the account.

Easy enough?

------------------
Goodbookmarks.com - Enjoy surfing the web once a day with us.
Submit Your Site Now!

They have: 850 posts

Joined: Jul 1999

O.k.

I just had to edit an older script I wrote to fit your needs.

Once you enter the email and username, it will check to see if the email is in the correct format, make sure the username isn't blank and make sure the username isn't in the database already. If there is an error(s) it will print out what they are.

If there are no errors, it will open up email.dat and print
$username:$email
and than print a success creen (which can be edited by yourself)

Someone will probably come a long with better code (Japhy ..) but if no one does, you can use mine (it has been tested and works on my machine.

Code Sample:

#!/usr/local/bin/perl
##############################################################################
# Customize Register  Script         Version 1.0                             #
# Copyright 1999 Rob Pengelly   [email protected]                               #
#                                                                            #
##############################################################################
#This script was created for  GoodBookMarks.com
#and may only be used there.
#
#

##########
#making variables that will be used later.
$numerror=0;
$success=0;
$indatabase=0;
@errors=();
##########
#Getting form input
&GetFormInput;
sub GetFormInput {

(*fval) = @_ if @_ ;

local ($buf);
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
}
else {
$buf=$ENV{'QUERY_STRING'};
}
if ($buf eq "") {
return 0 ;
}
else {
@fval=split(/&/,$buf);
foreach $i (0 .. $#fval){
($name,$val)=split (/=/,$fval[$i],2);
$val=~tr/+/ /;
$val=~ s/%(..)/pack("c",hex($1))/ge;
$name=~tr/+/ /;
$name=~ s/%(..)/pack("c",hex($1))/ge;

if (!defined($field{$name})) {
$field{$name}=$val;
}
else {
$field{$name} .= ",$val";

#if you want multi-selects to goto into an array change to:
#$field{$name} .= "\0$val";
}


   }
}
return 1;
}

##########
#The following are the variables that have been parsed
$email=$field{'email'};
$username=$field{'username'};
$pressed=$field{'pressed'};

##########
#The following will print the form to create a new login
if($pressed eq "")
{
print "Content-type:text/html\n\n";
®ister;
}
sub register
{
print <<EndHTML
<html>
<head>
  <title>[ Register ]</title>
</head>

<body bgcolor="white" text="black" link="black" vlink="gray">
<form action="/Cgi-Bin/register.cgi" method="POST">
<input type="hidden" name="pressed" value="pressed">
<table cellpadding="0" border="0" bordercolor="black" width="100"  bgcolor="white" celpadding="3" cellspacing="1">
  <tr>
    <td colspan="1" width="50%"><font size="2" face="verdana" color="gray"><b>User Name</b></font></td>
    <td colspan="2"><font size="3" face="verdana">
      <input name="username" type="text" maxlength="30" size="20">
      </font></td>
  </tr>
  <tr>
    <td colspan="1" width="50%">
    <font size="2" face="verdana" color="gray"><b>Your Email</b></font>
    <td colspan="2"><font size="3" face="verdana">
      <input name="email" type="text" maxlength="50" size="20">
      </font></td>
    </tr>
  <tr>
    <td colspan="1" width="50%"> 
    <td colspan="2"><font size="2" face="verdana" color="#F0F0F0">
      <input type="submit" value="Send">
      <input type="reset" value="Clear">
      </font><br>
       </td>
  </tr>
</table>
</form>
</body>
</html>

EndHTML
} #end sub register

##########
#Making sure the submit button was pressed before going on
if($pressed ne "")
{

#########
#Making sure email is in correct format
if ($email !~ /.+\@.+\..+/)
{
$error="The email that you entered was not in the correct format";
push(@errors,$error);
$numerror++;
}

##########
#Making sure a $username is not ""
if ($username=="")
{
$error="You forgot to enter a User Name";
push(@errors,$error);
$numerror++;
}


##########
#Check to see if $email is already in database


if($username ne "")
{

open(data,"<email.dat");

while(<data> )
{
$indatabase = 1, last if(/^$username:.+/i);
}
close(data);

if($indatabase==1)
{
$error="The username you entered is already in the database";
push(@errors,$error);
$numerror++;
}

}


##########
#The error message that will display if there is an error with the form
if($numerror>=1)
{
®ister;
}


if ($numerror==1)
{
print "<b>The following error was found in the form<\/b><br>";
print "-$errors[0]<br>";
print "<u>Please correct this error<\/u>";
}

if ($numerror>1)
{
print "<b>The following errors were found in the form<\/b><br>";
foreach $error(@errors)
{
print "-$error<br>";
}
print "<u>Please correct these errors<\/u>";
}

##########
#Add the new email and password to the database
if($numerror== 0)
{
open(IN,">>email.dat");
print IN "$username:$email\n";
close(IN);
$success=1;
}

if($success==1)
{
print "Content-type:text/html\n\n";
print <<EndHTML
<html>
<head>
  <title>[ Register ]</title>
</head>

<body bgcolor="white" text="black" link="black" vlink="gray">
Success, your account was created.<br>
Username: $username<br>
Email: $email<br>

</body>
</html>
EndHTML
}

}#end of if($pressed ne "")

------------------
An ostrich's eye is bigger than it's brain.

update

For some reason UBB is showing

®ister;
instead of
"&"register; (no space and leave out the quotes.

[This message has been edited by robp (edited 22 December 1999).]

They have: 850 posts

Joined: Jul 1999

Forgot to say that it should be named
register.cgi
unless you want to change the name of it in the register sub html.

------------------
Elephants are the only mammals that can't jump.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.