Simple login using PHP, Ajax and MySQL

In this tutorial I will be implementing a simple login using PHP, Ajax and MySQL that can be added to any PHP project to allow an admin to login to a website and get redirected to an admin page. The login system uses Ajax to communicate with the PHP and the database. It checks if the email and password exists and will redirect the user to any given location specified on the JavaScript and Index.php page.

Here is what the form looks like after it has been set up

Simple Login using Ajax and PHP
The web form has little styling but should be enhanced further by anyone who downloads the code and implements it in a project. The design is very bland and some colours could be added to suit your dynamic PHP web application. One area for improvement is security. The passwords are not Hashed, which means the application is not secure and would need additional security added on a production site. This simple application is designed to get a basic login system setup on a website and I encourage developers to enhance it further. We are using PDO to connect to the database, you can learn more about PDO on this blog article on the benefits of using PDO or on W3Schools.

You can see the project working on this – Live demo

To see the login in action use the following credentials:

User: admin Password: y75R1q4eWznk8

You can download – Simple login (825 downloads)

How to implement the Simple login using PHP, Ajax and MySQL code in a project

First you need to set up a database and run the following SQL to create a users table.

Then you will need to add an admin username and password in the database. After the database is set up and the files installed on a server, you should set the redirection to point to an admin area on your project. To set the redirect page, you will need to identify the page you want the user to be directed to in the index.php and the JavaScript file.

Below is a video tutorial showing how to set up the project on a remote server

Leave a Reply

Your email address will not be published.

XL Websites

XL Websites