PHP Login Script (PHP, MySQL, Bootstrap, jQuery, Ajax and JSON) Demo
More tutorials www.w3schools.in
Sometimes you may required to protect your web page with user authentication by 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 protected page.
- Login by using PHP script and MySQL database and only after authentication user can access to protected page.
- Foreign key relationships between MySQL tables.
- 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 is created in database to manage user and user profile data separately.
tbl_users
tbl_user_profile
Schema
- Foreign key relationships exist in between this two tables.
- User profile data will get deleted automatically if data deleted from users 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.