banner



How To Design A Register Page In Php

How to Create a Register and Login Folio Using PHP

PHP

In this article, we show how to build a register and login page using PHP.

A annals page or form tin can be used for your website to annals users in the event that your website takes in users. Mayhap your website uses members and you want to sign upwards members. Or maybe your site doesn't have members. You want to just take down information from users, for perchance like an email listing so that you can send them electronic mail. Withal, most of the time, it'south probably for members. It may not be for any type of social platform. Maybe you just want people on your site to have accounts, then that possibly they could upload documents or projects they've done.

For, example, this site doesn't have members (forum doesn't count). It doesn't sign upwardly members then that a member has his/her ain account. But if it did, it could be used for something like a fellow member trying to share his/her own electronic product or possibly code.

And then a register and login organization can exist used for something like that.

Annals Page

And so before nosotros have a login page, we demand to outset annals users. We need to kickoff go users in the database so that they are officially registered.

How we exercise this is we create a database through MySQL.

And then one time nosotros have this database, we apply a register form where a user can type in information, such every bit his/her start name, last name, username and password.

Once the user clicks the class submit button, this information is so sent and stored in the MySQL database.

And so what's the code to become about the create a annals form?

Code for Annals Folio

We will show and explicate the lawmaking needed to create the register page below.

You can as well run across information technology in the following text file at the post-obit link: Code for Annals Page.

PHP Code

The first block of lawmaking needed to brand this grade work is the PHP code.

And so with this PHP code shown to a higher place, nosotros create a connection to the MySQL database that will concord the user data from the register form. This MySQL table has v fields: ID, first name, last name, username, and password.

To connect to the database, we demand a host name, user proper name, countersign, database proper noun, and the name of the table which will concord the user information.

I created this table using phpMyAdmin.

The ID column is of type "int" and is set to auto-increase.

The first name cavalcade is of type "varchar" and is given a value of fifty.

The last name column is of type "varchar" and is given a value of l.

The username column is of type "varchar" and is given a value of 50.

The password column is of type "varchar" and is given a value of 50.

An prototype of the structure of this table tin be seen at the following link: Table for User Registration and Login.

Once nosotros have all of this fix, we retrieve data from the HTML course whose code is shown below.

This is done through the superglobal $_POST array. From the HTML class, nosotros obtain the first proper name, last name, username, and password entered in past the user. We too obtain data from the submit button see whether it has been clicked or not.

Nosotros then connect to the database using the mysql_select_db function.

Nosotros so query the database to find out whether the username that the user has entered. We shop this in the variable $username_table.

We then create a variable named $count and count how many rows exist based on this query. The reason nosotros do this is if the $count variable is equal to 0, this means that the username has not been taken, so this user tin use that user. If the $count variable is not equal to 0, this means that it is taken and this user cannot take it (since it's already been taken).

The side by side block of lawmaking has an if statement. If any of the variables, $firstname, $lastname, $username, and $password1 are empty, then nothing that the user entered into the register grade will be transferred to the MySQL tabular array.

If the fields are not empty (the user has entered into all of them), then there is i more than if statement. If the $count is equal to 0, then we insert the information that the user has entered into the form into the MySQL database table. Remember the $count variable holds whether the username is taken or not. If it is 0, this means the username that the user has entered is non taken and thus can be used. If information technology is not 0, the username is taken; thus we cannot add together it to the table (this would create indistinguishable usernames which of grade is forbidden).

The last line simply closes the database connexion. Since we've already inserted the data from the HTML form into the MySQL table (if the username wasn't taken and the class fields were all entered), nosotros can shut the connexion to the database and its table.

This is all the PHP code needed to create the annals course.

HTML Code

The HTML code for the register form is shown beneath.

Then the above lawmaking creates the form needed in which the user volition input data.

In this course, we create 4 text boxes. The text boxes asks for the user's showtime name, last proper noun, username, and password.

All the text boxes are of type "text" except the countersign textbox. The password text box takes on the type "password", so that the characters entered into information technology are encrypted. Otherwise, it is just like the other text boxes.

For each of the text boxes, the text box cannot exist left bare; else, the form will output, "This field cannot be left empty". How we do this is through ii if statements for each text box. The first if statement checks the variable $submitbutton. This variable holds whether the submit button of the form has been clicked. If the submit button has been clicked, information technology will exist true. If the submit push button has not been clicked, it'due south false. If the submit button has been clicked and the field is empty, and then the statement, "This field cannot be left empty" volition be output.

For the username text box, there is an additional if statement. If the submit push has been clicked and the $count variable is not equal to 0, this ways this username has already been taken (since information technology's already present in the database.

Lastly, we have the submit button. We name this button "submit".

This completes all of the code needed to create the register page.

Login Page


Side by side we need the login folio.

Code for Login Folio

And so now we go over the lawmaking for the login page.

This code is shown below.

The code for the login page is very simple. Information technology is simply an HTML class.

The form contains the fields, Username and Passworld.

These are the but fields required for a user to log in.

The course, as just forms crave, needs a submit button.

One time clicked, the form redirects the user to the PHP page, login-confirmation-page.php using the POST method.

Over again, this is all that is required for the login page.

Login Confirmation Page

The final folio is the login confirmation folio. This is the page the user gets brought to afterwards s/he has logged in.

One time you utilise the login page, you'll be brought to the confirmation page.

Lawmaking for the Login Confirmation Page

The lawmaking needed for the login confirmation page, which is entirely PHP lawmaking, is shown below.

So, once again, we create our connection to the MySQL database table.

We then take the login information from the login form that the user entered in through the superglobal $_POST array. These are the $username, $password1, and $submitbutton variables.

We make the connection to the database.

We then query the table of the database to see whether the username that the user has entered exists or not.

We also store the values of the first name, last name, and password of that username (assuming information technology exists).

We then use an if statement. If the $count variable is 0, this means that the username that the user entered does non exist. So we echo the argument, "Deplorable, login was not successful. The username entered does not exist" We then redirect the user back to the login page to retry.

If the $count variable is equal to one and the password entered doesn't match the countersign in the database, we echo the statement, "Sorry, login was non successful. The password entered was incorrect." Nosotros, again, redirect the user dorsum to the login page to retry.

If the $count variable is equal to i and the password entered matches the password in the database, we echo "Hullo" and the user's proper noun. The ucwords() function capitalizes the user'south name in the event that the user entered his/her name in lowercase. Nosotros too echo to the user, "you lot have been successfully logged into your business relationship".

And this is all that is required to make a simple register and login page using PHP.

Of form, there are many variations that can be done to this register and login page.

For example, in the register form, we can new form fields such as become the user's gender, appointment of birth, whatsoever other information, etc. Withal, the more uncomplicated and invasive a form field, the more a user volition trust it. However, you can add together how many information fields you want. It'south besides based on what type of site yous're running. Depending on what site you run determines what information you may demand a user to reveal.

Besides the form fields, nosotros can make information technology and so that the user can have a countersign reset option in the login form. We will reveal the modifications needed to create a password reset selection, then that if the user forgets his countersign, he tin reset information technology. This isn't hard. We merely have to create another page where the user types in his username. We then create a connection to the table of the MySQL database and rewrite the current password in the countersign field.

There are many variations. Nonetheless, this grade can exist used as a fundamental root of what is necessary to create a register and login page using PHP.

Using only PHP, we can create a pretty decent register and login class using PHP.

It's decent just it isn't equally skillful as if you had jquery code involved. This is because we must submit the form in guild to find out whether a username is taken. Modern upward-to-date companies allow you to tell whether a username is taken without a user having to click the submit button of a form. This is more efficient.

However, again, for a basic register and login folio for your site, the lawmaking in a higher place runs very well.

Also, this page shows just how to create a register and login page. One more element that needs to be added and considered is the session_start() part in PHP. For case, once a user logs on into his account, once he will switches to another page on the site, yous still want him to be logged on. Therefore, in one case a user logs on, we have to start a session, and so that he remains logged on while maneuvering through the site. To meet a total tutorial on session, see How to Use Sessions to Track User Data Using PHP. This will show you lot how once a user has registered in, how we tin proceed the user logged in even while the user visits different pages on the site. You don't want the user'due south session to stop after the register page. You want to user to remain logged in until the user logs off. To do this, you need to start a session once the user has logged in. This keeps the user's log in session lasting even while the user visits other pages on the site.

Related Resources

How To Design A Register Page In Php,

Source: http://www.learningaboutelectronics.com/Articles/How-to-create-a-register-and-login-page-using-PHP.php

Posted by: maneenturnew.blogspot.com

0 Response to "How To Design A Register Page In Php"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel