PHP Login Script (PHP, MySQL, Bootstrap, jQuery, Ajax and JSON)

Sometimes you may require protecting your web page by user authentication using the database, and this tutorial can help you to do it.
This tutorial demonstrates user registration and login process by using PHP and MySQL.

Features

  • Complete user registration and login management system.
  • User registration data store in MySQL database.
  • Login by using PHP script and MySQL database and only after authentication user can access to the protected page.
  • Login by using PHP script and MySQL database and only after authentication user can access to the protected page.
  • Foreign key relationships between MySQL tables.
  • The user can Logout after Login.
  • PHP session is used to keep user login status until logout is clicked.
  • Secured code to prevent SQL injection attacks.
  • Data transmission by using JSON.
  • Bootstrap has been used to improve the user interface.
  • jQuery Ajax is used to submit forms without refreshing the page.

Database Structure

Two tables are created in the database to manage user and user profile data separately.

tbl_users

DB_tbl_users

tbl_user_profile

DB_tbl_user_profile

Schema

DB_schema

  • Foreign key relationships exist in between this two tables.
  • User profile data will get deleted automatically if data deleted from the user's table.

Program Structure

PHP

  • /index.php - This page can only open after authentication, otherwise user will be redirects to main.php page.
  • /main.php - This page only contains HTML login and registration forms.
  • /submit.php - PHP codes for Login and registration exist in this page, submitted by main.php page.
  • /logout.php - This page is destroying the session started by submit.php page.
  • /inc/config.php - This page is included in all php pages and used to start session and connect with MySQL database.
  • /inc/functions.php - This page has contains custom PHP functions used in program.
  • /include/header.php - This page has contains html.
  • /include/footer.php - This page has contains html.

JS

  • /js/app.js - This page has contains custom JavaScript which is used to submit Login and Registration forms.
  • /js/jquery.min.js - jQuery Plugin.
  • /js/bootstrap.min.js - Bootstrap Plugin.

CSS

  • /css/style.js - This page has contains custom CSS.
  • /css/bootstrap.min.css - Bootstrap Plugin.