| |||||||
This is a discussion on PHP User Registration System within the PHP/MySQL section, part of the Programming category; Introduction (Must read) Here's a tutorial for building a complete registration system in PHP/MySQL that can be easily implemented on ...
![]() |
| | LinkBack (1) | Thread Tools | Display Modes |
#1
| ||||
| ||||
| Introduction (Must read) Here's a tutorial for building a complete registration system in PHP/MySQL that can be easily implemented on your PHP website. Email address is verified by sending a confirmation mail. The passwords are encrypted via strong sha256 algorithm. Summary of Process:-
__________________ Would you like to Link To Us | Support TECH6 by going Premium Know more about me at Vinayaks.com | Follow TECH6 at Twitter |
|
#2
| ||||
| ||||
| Part II - Account Confirmation or Email Authentication Part III - Forgot Password feature Implementation Part I - User Registration System Setup 1. Building the Registration form (register.php):- a) Designing the form:- I won't be giving a tutorial for designing a form that includes your colors and CSS. Simply use your favorite HTML editor like Adobe Dreamweaver. You must start your <form> tag declaration like this, so copy it. I don't think it needs description. HTML Code: <form action="<?php echo $editFormAction; ?>" METHOD="POST" name="registerform"> Additionally, create 3 hidden fields (Copy/Paste the code below anywhere within <form> tag):- HTML Code: <!-- Grabbing IP of user --> <input type="hidden" name="ip" id="ip" value="<?php echo $_SERVER['REMOTE_ADDR'];?>" /> <!-- Grabbing current date --> <input name="joindate" type="hidden" id="joindate" value="<?php echo date("F j, Y");?>" /> <!-- Required for inserting records into the table from registerform --> <input type="hidden" name="MM_insert" value="registerform" />
__________________ Would you like to Link To Us | Support TECH6 by going Premium Know more about me at Vinayaks.com | Follow TECH6 at Twitter |
|
#3
| ||||
| ||||
| b) Validating the fields:- Simply refer to this post. It has complete documentation and example on validating fields. However, the documentation provided in the above post won't be sufficient for our registration form as our requirement is somewhat more complex. So, here is exact code you need according to the above field names that is to be put right after </form> tag. You may edit the input limits as desired. Code: <script language="JavaScript" type="text/javascript">
//You should create the validator only after the definition of the HTML form
var frmvalidator = new Validator("registerform");
frmvalidator.addValidation("email","maxlen=50");
frmvalidator.addValidation("email","req","Please enter your Email Address !!");
frmvalidator.addValidation("email","email","Please enter a valid email address !!");
frmvalidator.addValidation("password","req","Please enter a Password !!");
frmvalidator.addValidation("password","minlen=5",
"Min length for Password is 5");
frmvalidator.addValidation("repassword","req","Please retype your Password !!");
frmvalidator.addValidation("firstname","req","Please enter your First Name !!");
frmvalidator.addValidation("firstname","maxlen=30",
"Max length for FirstName is 30");
frmvalidator.addValidation("firstname","minlen=3",
"Min length for FirstName is 3");
frmvalidator.addValidation("firstname","alpha");
frmvalidator.addValidation("lastname","req","Please enter your Last Name !!");
frmvalidator.addValidation("lastname","maxlen=30",
"Max length for LastName is 30");
frmvalidator.addValidation("lastname","minlen=3",
"Min length for LastName is 3");
frmvalidator.addValidation("lastname","alpha");
frmvalidator.addValidation("city","req","Please enter your City !!");
frmvalidator.addValidation("city","maxlen=20",
"Max length for City is 20");
frmvalidator.addValidation("city","alpha");
frmvalidator.addValidation("country","dontselect=0","Select your country !!");
frmvalidator.addValidation("date","dontselect=0","Select your Date Of Birth !!");
frmvalidator.addValidation("month","dontselect=0","Select your Month of Birth !!");
frmvalidator.addValidation("year","dontselect=0","Select your Year of Birth !!");
//*************************************************************
//Custom Validating Agreement and Password Fields
//*************************************************************
//Matching Password Fields
function DoMyValidationOne()
{
var frm = document.forms["registerform"];
if(frm.password.value != frm.repassword.value)
{
alert('Password Fields do not match !!');
return false;
}
else
{
return true;
}
}
frmvalidator.setAddnlValidationFunction("DoMyValidationOne");
//Accepting Agreement
function DoMyValidationTwo()
{
var frm = document.forms["registerform"];
if (frm.acceptance[0].checked)
{
alert('You must ACCEPT our Terms and Conditions/Privacy Policy in order to register with my Site !!');
return false;
}
else
{
return true;
}
}
frmvalidator.setAddnlValidationFunction("DoMyValidationTwo");
function DoCustomValidation()
{
var frm = document.forms["registerform"];
if(false == DoMyValidationOne())
{
return false;
}
else
if(false == DoMyValidationTwo())
{
return false;
}
else
{
return true;
}
}
frmvalidator.setAddnlValidationFunction("DoCustomValidation");
//**********************************************
//End of Custom Validation
//**********************************************
</script>
Code: <script language="JavaScript" src="gen_validatorv2.js" type="text/javascript"></script>
__________________ Would you like to Link To Us | Support TECH6 by going Premium Know more about me at Vinayaks.com | Follow TECH6 at Twitter |
|
#4
| ||||
| ||||
| 2. Getting ready with the Database:- One good program I always use and recommend is SQLYog to directly connect to/or modify your database. It has a Community Edition which is free. Otherwise you can use any other program such as phpmyadmin. We need two tables:
Create table temp_data in the following way:- ![]() Create table registered_users in the following way ![]()
__________________ Would you like to Link To Us | Support TECH6 by going Premium Know more about me at Vinayaks.com | Follow TECH6 at Twitter |
|
#5
| ||||
| ||||
| 3. PHP Code Implementation:- Right, so easy part is over. Now we move on to the actual PHP code implementation in register.php where we check for existing email address, insert the records and encrypted password into temporary table in the database and at last dispatching the activation email with a unique link generated. Starting off with connection.php that is required to connect to database. Copy it as it is. PHP Code: Note: You or/and your host knows best what values to be put for above variables. Now, first download the SHA256.INC, unzip and upload the .php file alongwith connection.php. (This is optional and do it ONLY if you have PHP4) Here's the PHP code required that goes right at the beginning of the register.php page i.e. before the <form> and other HTML/CSS code (Please read the comments to understand code better) PHP Code: ![]() You should test the complete process uptill now. It should:-
Part I ends here
__________________ Would you like to Link To Us | Support TECH6 by going Premium Know more about me at Vinayaks.com | Follow TECH6 at Twitter |
|
#6
| ||||
| ||||
| Part II describing what to do next coming soon !!
__________________ Would you like to Link To Us | Support TECH6 by going Premium Know more about me at Vinayaks.com | Follow TECH6 at Twitter |
|
#7
| ||||
| ||||
|
useful information but i need some more basic think like installation process for php |
|
#8
| ||||
| ||||
|
This thread does not deal with the issue of installing PHP. Anyways we always use a testing server to upload and test .php or any other server side scripting languages and hardly install PHP on our own PC. Still if you want, check out a tutorial to Install PHP on Windows. And another nice tutorial here.
__________________ Would you like to Link To Us | Support TECH6 by going Premium Know more about me at Vinayaks.com | Follow TECH6 at Twitter |
|
#9
| ||||
| ||||
|
great effort.. thank you for providing such a nice tutorial and links webwizzy..The user registration system is well described...keep it up lol.. regards spec_tray |
|
#10
| ||||
| ||||
|
ha.. thanks for the compliment dear, I had been writing this since a week to post it here. There's yet a lot more to go in it.
__________________ Would you like to Link To Us | Support TECH6 by going Premium Know more about me at Vinayaks.com | Follow TECH6 at Twitter |
|
#11
| ||||
| ||||
|
Go on mate .. so that i can also learn some php from here..:wink: regards spec_tray
__________________ " There are no failures - just experiences and your reactions to them. New members Please read before u post General Tech6 Rules !!! CSS Validator | Markup Validator | RSS Validator |
|
#12
| ||||
| ||||
|
Your tutorial was very helpful and concise, however I need additional help. I understand how to setup a user registration system but I need help with AFTER they register. I'll explain my scenario: I have a website that sells items that require users to upload pictures and copy(paragraphs/text). After they register how do I make it so users can select my item and upload their content. Then after they upload it stores all THEIR content on the database? I need to make it so I can pull down each user's content i.e. pictures and text from the database. Please help out a.s.a.p. thank you. |
|
#13
| ||||
| ||||
|
hii sogah and welcome to tech6 forums. well.. I don't find your query anywhere related to user registration system. Its a different topic on how to UPLOAD content onto the database through php. Kindly start a different thread on how to go about doing this so fellow members can have a look at it too. By the way, a quick google search revealed these tutorials:- http://www.w3schools.com/PHP/php_file_upload.asp http://www.tizag.com/phpT/fileupload.php http://www.phpeasystep.com/workshopview.php?id=2 Also, here's a nice tutorial on Uploading Files To MySQL Database Hope this helps !
__________________ Would you like to Link To Us | Support TECH6 by going Premium Know more about me at Vinayaks.com | Follow TECH6 at Twitter |
|
#14
| ||||
| ||||
|
is it possible to create a pop-up error message for validation? for example if the passwords do not match and the user clicks submit, instead of displaying echo 'passwords do not match' a pop-up error message window appears. Similar to windows error messages. |
|
#15
| ||||
| ||||
|
sorry.. I did not understand sogah ! Even the current one is a javascript pop-up error message, so I'm not sure what you are talking about. Can you explain in more detail or via screenshot! Thanks
__________________ Would you like to Link To Us | Support TECH6 by going Premium Know more about me at Vinayaks.com | Follow TECH6 at Twitter |
|
#16
| ||||
| ||||
|
Great Tutorial Post WebWizzy. I'm sure members will find this very useful. You have explained this process in an easy to follow manner. Well done |
|
#17
| ||||
| ||||
|
you are my man When can i see the next part 2,3,4 ? looking forward to doing your stuff more |
|
#18
| ||||
| ||||
to tech6glad you like it runforest and thanks for your feedback at Vinayaks.com ![]() Not now.. but very soon as and when I get time.
__________________ Would you like to Link To Us | Support TECH6 by going Premium Know more about me at Vinayaks.com | Follow TECH6 at Twitter |
|
#19
| ||||
| ||||
|
There could be a conflict in naming of your database fields the confirmcode isnt it the same as passcode ? if it is, you should have put confirmcode and forget_confirmcode instead of forgot_passcode. But thats my preference when naming fields, making a consistent meaning. As long as the codes work, its cool. |
|
#20
| ||||
| ||||
|
All what matters is the correct column name in the code. So, personally I don't see any chance of *conflict* in that. As far as fields/variable naming thing is concerned, then yes, it could had been what you said for kind of better understanding. But confirmcode/passcode hardly matters lol, coz they are almost similar. Btw.. its just a tutorial/guideline to get things started, not a readymade script to install. There's a lot of things to adjust in it, so feel free to add and edit your fields/variables too. Also, seeing your interest, I'd like to tell you that there's a lot of scope of optimization that can and should be done to the code which I have learned a bit later. I'll suggest you:- To completely discard the use of temp_data table and make a new column in registered_users table called activated that stores a value of 0 (for unactivated users) and 1 (for activated users). There's nothing much do in this case, just insert the default value 0 into the new activated column and despatch the email. When the user follows the URL in the activation email, simply update the activated column with value 1 for that user (this saves the delete query from temp_data as well as an insert query in registered_users table) You can then query all your registered/activated members with:- PHP Code:
__________________ Would you like to Link To Us | Support TECH6 by going Premium Know more about me at Vinayaks.com | Follow TECH6 at Twitter |
![]() |
| Bookmarks |
| Tags |
| tutorial, user registration system |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://tech6.com/f19/php-user-registration-system-t145/ | ||||
| Posted By | For | Type | Date | |
| PHP User Registration System | This thread | Refback | 15-09-2009 01:33 PM | |