Jump to content
xisto Community
Sign in to follow this  
Houdini

What Would Make A Good Registration Script?

Recommended Posts

I see newbies all the time looking for either a login script or after a little querying you find they really would like to have a registration script. The first thing for such a script for a members area would of course be a form and being kind of old fashioned I still like to format my forms with a table but I do use inline CSS to make it a little nicer. I never did like forms that had an asterick * by a field and then a Note: Fields marked with * are required. So what I do instead is add a background color to those areas and then use a CSS background color stating that thise text boxes or whatever are required. Here is a form that I use for a registration.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head> 
     <title>Registration</title>
     <meta http-equiv="generator" content="PHP Designer 2006 - BETA" />
  </head>
  <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  <center><h2>Welcome to the Registration Page.</h2></center>
  <div align=justify><font size=-1 color=blue><center><h4>Terms of Service</h4></center>This site is for those that are at least of the age of 18 or older. If you are not at least 18 or older then you must have your parents permission to sign up and they must actually sign up for this page and use theinformation for your account that they provide. With this in mind it is understood by filling out this application that you are the parent or legal guardian of a minor and are signing up for an account. Poronography suggestive photographs or solicitation of prostitution is forbidden on this site. By filling out the form below you are stating that you will abide by the above. If you have lied about your age or identity, your account may be terminated without notice, and possbile prosecution may also result from your actions with the account if granted. Please keep in mind that any content provided by you should be civil in nature and not advocate the overthrow of the United States Goverment or any state therein.</font></div><br /><br /> 
    <table border=1 bordercolor=lightblue width=100%>
	<form action='processing2.php' method='post'>
		<tr><td><input type='text' name='firstname' style='background:aqua' value='
		<?php echo $_POST['firstname']; ?>' /><-Enter First Name</td>
		<td><input type='text' name='lastname' style='background:aqua' value='
		<?php echo $_POST['lastname']; ?>' /><-Enter Last Name</td>
		<td><input type='text' name='username' style='background:aqua' value='
		<?php echo $_POST['username']; ?>' /><-Enter preferred username</td></td></tr>
		<tr><td><input type='password' name='pass' style='background:aqua' value='
		<?php echo $_POST['pass']; ?>' /><-Enter preferred Password</td>
		<td><input type='password' name='pass2' style='background:aqua' value='
		<?php echo $_POST['pass2']; ?>' /><-Confirm Password</td>
		<td><input type='text' name='email' style='background:aqua' value='
		<?php echo $_POST['email']; ?>' /><-Enter a valid E-mail</td></tr>
		<tr><td><input type='text' name='address' value='
		<?php echo $_POST['address']; ?>' /><-Street Address</td>
		<td><input type='text' name='city' value='
		<?php echo $_POST['city']; ?>' /><-City</td>
		<td><input type='text' name='state' value='
		<?php echo $_POST['state']; ?>' /><-State</td></tr>
		<tr><td><input type='text' name='zip' value='
		<?php echo $_POST['zip']; ?>' /><-Zip Code</td>
		<td><select name='dobm' style='background:aqua'>
		<option value='1'>01</option>
		<option value='2'>02</option>
		<option value='3'>03</option>
		<option value='4'>04</option>
		<option value='5'>05</option>
		<option value='6'>06</option>
		<option value='7'>07</option>
		<option value='8'>08</option>
		<option value='9'>09</option>
		<option value='10'>10</option>
		<option value='11'>11</option>
		<option value='12'>12</option>
		</select>
		<select name='dobd' style='background:aqua'>
		<option value='1'>01</option>
		<option value='2'>02</option>
		<option value='3'>03</option>
		<option value='4'>04</option>
		<option value='5'>05</option>
		<option value='6'>06</option>
		<option value='7'>07</option>
		<option value='8'>08</option>
		<option value='9'>09</option>
		<option value='10'>10</option>
		<option value='11'>11</option>
		<option value='12'>12</option>
		<option value='13'>13</option>
		<option value='14'>14</option>
		<option value='15'>15</option>
		<option value='16'>16</option>
		<option value='17'>17</option>
		<option value='18'>18</option>
		<option value='19'>19</option>
		<option value='20'>20</option>
		<option value='21'>21</option>
		<option value='22'>22</option>
		<option value='23'>23</option>
		<option value='24'>24</option>
		<option value='25'>25</option>
		<option value='26'>26</option>
		<option value='27'>27</option>
		<option value='28'>28</option>
		<option value='29'>29</option>
		<option value='30'>30</option>
		<option value='31'>31</option>
		</select>
		<select name='doby' style='background:aqua'>
		<option value=1930>1930</option>
		<option value=1931>1931</option>
		<option value=1932>1932</option>
		<option value=1933>1933</option>
		<option value=1934>1934</option>
		<option value=1935>1935</option>
		<option value=1936>1936</option>
		<option value=1937>1937</option>
		<option value=1938>1938</option>
		<option value=1939>1939</option>
		<option value=1940>1940</option>
		<option value=1941>1941</option>
		<option value=1942>1942</option>
		<option value=1943>1943</option>
		<option value=1944>1944</option>
		<option value=1945>1945</option>
		<option value=1946>1946</option>
		<option value=1947>1947</option>
		<option value=1948>1948</option>
		<option value=1949>1949</option>
		<option value=1950>1950</option>
		<option value=1951>1951</option>
		<option value=1952>1952</option>
		<option value=1953>1953</option>
		<option value=1954>1954</option>
		<option value=1955>1955</option>
		<option value=1956>1956</option>
		<option value=1957>1957</option>
		<option value=1958>1958</option>
		<option value=1959>1959</option>
		<option value=1960>1960</option>
		<option value=1961>1961</option>
		<option value=1962>1962</option>
		<option value=1963>1963</option>
		<option value=1964>1964</option>
		<option value=1965>1965</option>
		<option value=1966>1966</option>
		<option value=1967>1967</option>
		<option value=1968>1968</option>
		<option value=1969>1969</option>
		<option value=1970>1970</option>
		<option value=1971>1971</option>
		<option value=1972>1972</option>
		<option value=1973>1973</option>
		<option value=1974>1974</option>
		<option value=1975>1975</option>
		<option value=1976>1976</option>
		<option value=1977>1977</option>
		<option value=1978>1978</option>
		<option value=1979>1979</option>
		<option value=1980>1980</option>
		<option value=1981>1981</option>
		<option value=1982>1982</option>
		<option value=1983>1983</option>
		<option value=1984>1984</option>
		<option value=1985>1985</option>
		<option value=1986>1986</option>
		<option value=1987>1987</option>
		<option value=1988>1988</option>
		<option value=1989>1989</option>
		<option value=1990>1990</option>
		<option value=1991>1991</option>
		<option value=1992>1992</option>
		<option value=1993>1993</option>
		<option value=1994>1994</option>
		<option value=1995>1995</option>
		<option value=1996>1996</option>
		<option value=1997>1997</option>
		<option value=1998>1998</option>
		<option value=1999>1999</option>
		<option value=2000>2000</option>
		</select><-Date of Birth (M-D-Y)
		</td>
		<td><input type='text' name='occupation' value='
		<?php echo $_POST['occupation']; ?>' /><-Occupation</td></tr>
	</table><br />
		<center>
		<span style='background:aqua'>Aqua colored fields are required!</span><br /><br />
		</center>
		I am over 18 year old or I am the parent or guardian
		<input type='radio' name='age' value='yes'  />Yes
		<input type='radio' name='age' value='no'  />No<br />
		I agree to the <span style='color:blue'>Terms of Service</span>
		as shown above the form.
		<input type='radio' name='tos' value='yes' />Yes
		<input type='radio' name='tos' value='no' checked />No<br />
		<center><input type='submit' name='register' value='Register' style='background;lightcoral'>
	  </form>
  </body>
</html>

It might be a lot of coding but it only need made once and your new users will be spending some time with it. So to avoid data errors and to make date entry into my database easier this is why I use the three drop down select boxes. I prefer to use the PHP only to retain values entered into the various fields in the event on the next page there are errors. Also required but not expressly stated are the two radio button groups for age and the Terms of Service aggrement, which is the first thig checked for in the processing page.

 

Then of course you will want to process this page when the user has hopefully filled out the thing entirely and with no mistakes like the confirmation of the password. So the very first thing I check for in the next page is the following; pressed submit, checked yes to the age and the Terms of Service.

if($_POST['register']=='Register' && $_POST['tos']=='yes' && $_POST['age']=='yes'){
Then I check for blank required and generate an error for each one that is to be shown for each error, or if it is correct then I assign a $_SESSION variable to the $_POST value for later use. I start a session at the beginning of the script so I can assign and use $_SESSION variables, and also trim all the $_POST variables with

$firstname=trim($_POST['firstname']);$firstname=addslashes($firstname);//in case of apostrophes$lastname=trim($_POST['lastname']);$lastname=addslashes($lastname);//in case of apostrophes...
I also use addslashes with cities because there are some like the one in Idaho that I can't remember nor could I spell, but it does have an apostrophe in it.

 

I also generate a random number with this script that will be sent out in the email that is sent for the new member to use to activate their acoount. Yes my processing page also send out email and it inserts the information that the user filled out and puts it into a database table named temp, which is purged within 24 hours. One of the fields will have this random number inserted into it as well as all the normal data that will be transferred to the permanent members table.

 

I said that the first check I made was if the usen hit submit, and the two TOS and age requirements but actually the first thing I check is if the username the new member enters is already in use if it is the file ends with a message that the username they chose is already taken and to hit the back button and try again. Then of course after checking for blank required fields there is a second check for the email validity which is the most you can do short of sending a mail and waiting for a read reciept so I merely use a regex (regular expression) like this.

if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)){			$error.=("The e-mail address you entered is invalid.<br />");			$num++;
Other than sending an HTML email using the mail() function that is about all that goes on other than the message that shows the information entered by the user (provided everthing else is correct). In this section I give them the option to go ahead and activate from this same script by going to an action.php page which will have another form but this one only asks for the Username Password and the activation code which is presented on the page here. This is optional because the email has a link that goes to another page activation.php the link sent in the email looks like this;

click on the following link <a href='http://localhost/activate.php?active=$random'>
[url="LOCALHOST/activate.php?active=$random"]http://localhost/activate.php?active=$random</a>[/url]

also within the email I let those that use AOL know that they might have to copy and paste the activation link into their browser (I think the AOL email client is kind of stupid).

 

So basically with my registration there are four pages one with the actual form shown above one that checks all the inputs accesses the database and checks to be sure that the username it not already in use by looking at the member table then another page for instant activation which will then check the newly entered data that is in the temp table to be sure they have the correct random number and if so will then insert the users data into the members table and then delete the information that is in the temp table, and an activation page that is accessed with the email link that the processing page created and then do the same as the last mentioned page.

 

I am sure there are more improvments that can be made to what I already have and ocassionally I look at ways to maybe make some improvements but as it is so far is it satisfactory and does what it is supposed to do. If any body has any ideas for other features or requirements for a registration and processing script then post them in this area. I would like to see them.

Share this post


Link to post
Share on other sites

I may be asking a stupid question here but, how do the different pages (except for the activation) know what is going on with each other? I'd like to use some of the ideas in this script, now that I've learned a little from trial and error, but just a little unsure of how to connect them all.EDIT-When asking user to confirm password (pass2) does that have to be written in the database as well?

Edited by lonebyrd (see edit history)

Share this post


Link to post
Share on other sites

The 'enter' page was so slow, but then I had to wait while it was loading the next page too. That is going to keep many visitors away. If I wasn't going to give feedback, I wouldn't have waited. But then I gave up when everything on the site took so long to load. But as for the site itself, I like the colors. The picture of the band (if that's what they are) are a little hard to see. But overall I liked what I did see of it.

Share this post


Link to post
Share on other sites

I may be asking a stupid question here but, how do the different pages (except for the activation) know what is going on with each other? I'd like to use some of the ideas in this script, now that I've learned a little from trial and error, but just a little unsure of how to connect them all.

 

EDIT-When asking user to confirm password (pass2) does that have to be written in the database as well?

 

Pages don't know what is going on with the other they can only information from one and compare it to known values that should be. As far as confirming passwords if they do not match on the second page then there will be an error, and this can happen. Suppose that in the first password text box the user typed mistletoe and in the second confirmation password text box they typed mistertow or eve missletow two of these sound the same but are not the same and one is completely wrong. The confirmation password is not needed in the database but just for the purposes of registration only and it ensures that the user is certain about the word or group of characters they are using for a password.

 

The reason there is logic provided by a processing page is to determine just what has happened with other code elsewhere. Logic in a computer program is basically just a bunch of test for a true or false condition and the action to be taken with the result of the outcome of each condition. A simple pseudo code would look like:

if(it is raining)  { //start first if  Watch movies on television  	 if(television is broken or there are no movies on it)	 {//start nested if	  listen to the radio	 }//end nested if		else 	   {		go to sleep till movies are on or television gets fixed or replaced	   }//end else  }//end first ifelse //if the first if fails then do this{Cut the grass and tend the garden}
The options are limited to the programmer (you maybe someone else) to develop what occurs when certain conditions are either true or false. So a careful analysis of what should or should not occur with any given condition within your program before you even start writing it. The outcome of your program depends on how well you develop the logic. Of course the above is ridiculous kind of logic and has room for improvement and that is up to the programmer in the first place.

 

Take all possibilities into consideration and decide beforehand how to handle them and your code will work much better when carefully planned. Remember the biggest room in the world is ROOM for IMPROVMENT.

Share this post


Link to post
Share on other sites

How do I process the email, and regsitration.

What Would Make A Good Registration Script?

 

I am very new at this, but am figuring it out pretty well as I go. But, how do I build this whole thing so that it works. I got the registration form how I want it and selecting the register button connects to the page I want it to, but I don't know how to setup the user database, email confirmation, and accessible pages as well as anything else related to having the members only section.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.