This is a tutorial, specially to guide the PHP beginners, to code a complete Login System. Here we will be learning, Creating Database, posting Form values, creating Session value and then destroying the Session value. It is very useful and simple.
Users Table: (This table is made based on our requirements, here we are just including username and password.)
Adding Data to the Database
Simply add the data to your database, enter atleast 2 rows, with uid (1 and 2) .
In db.php you must change the SERVER_NAME, USERNAME, PASSWORD and DATABASE to your own MySql settings.
Contains Php and HTML code. It holds the Login form.
Includes Php code to compare Form input values with the database values.
This is the home page, shown after successful login.
To destroy session, and to take the user back to Index page.
- Index.php is to show the Login Form, Post values from the form to Check.php and also to show error messages based on "attempt" value.
- Check.php is to check the values entered by the user and compare it with the ones stored in database. If matched then direct user to Homepage else show error.
- Home.php is the Homepage and LogOut.php destroys the session and directs user back to the Login page.
If you face any kind of problem in this simple tutorial, feel free to let me know through your comments.