Simple Login and Signup System using PHP and MySQLi

hello friends, we already have this tutorial but using MySQL extension but that's deprecated now and some users want it using MySQLi extension, so i have decided to post Login and Registration System using PHP with the improved MySQLi. it's a simple script which you can easily understand. for the designing purpose i have used here bootstrap to create login and signup form which is simple and easy to create with the help of bootstrap, if you are using PHP5.5 then you must use new password hashing function, you can see it how to use them here in this tutorial, Login script with MySQL so let's take a look.

register.php

this is our registration/signup page for the new user and it will ask username, email and password to enter, i have skipped here validation part and used HTML5 required client side validations to validate the form and the form was created with bootstrap. password_hash($upass, PASSWORD_DEFAULT); it will make password stronger than MD5.

index.php

this is our login page which will ask users to enter email and password to go the home page which is members page, to use database we have to include "dbconnect.php" file. i have used here password_verify($upass, $row['password']) to verify password this is new password hashing functin and you have to use PHP5.5 to use this function.

home.php

if user successfully logged in he will be redirected to this "home.php" page, this is members page only registered users can access this page, contains bootstrap header with menu and one link to logout.

That's it, we have covered here a simple login and registration system using PHP and MySQLi, the reason behind posting this tutorial is, i got few emails regarding MySQLi login and signup script, so i have posted it here. if you like it please share it with your social media friends, thank you :)

on the register.php replace $new_password = password_hash($upass, PASSWORD_DEFAULT); on line 15 with $new_password = md5($upass); also on the index.php replace if(password_verify($upass, $row['password'])) on line 19 with if(md5($upass, $row['password']))

hi, i have an error in register.php. when i want to register another account, it said error while registering.is it have problem with the if($count==0)?because when i manually increase the user_id in database from 0 to 1 or 2(not 0), then it will display successfully registered. please, Help me. :(

Hello Lytron, sorry for the trouble with your code, please make sure you have created database table properly and comply with this code, or please try to echo insert query while signing up, you may there get your error.

Hello, i realli like this script! I need to have it so that only users that have the "activated" value of 1 can view the home.php. Users who are not yet been activated will see a different page. Can you please implement this in the script or paste a line here that will make this work? Thank you in advance.

Worked for me! I just had to adjust the password to connect to phpMyAdmin on the dbconnect.php file. Thanks for the helpful code! I really appreciated this after looking for almost a week for something like this.

Hi can you do a profile page that they can edit their names, ages, address, etc. i tried changing the register.php to just retrieve the data but when i change the select to update it wont do anything. thanks in-advance

Me too has been looking a long time for something like this. I like it - and it works, which is important. My problem is that I am not able to change from being directed to home.php after I have log in. In your earlier version and on xampp it worked with replacing home.php but not live with this version. Only get a blank page. I am a newbie and of course lack of knowledge.

You can't only trust to escape strings. You must use prepared statements on your every sql connection. Even things like user login system, it's a must. Without prepared statements no one should use this codes.

But thanks anyway, it rare to find login codes with new 5.5 functions.

Hi there, Really appreciate the script, very helpful for beginners! However, I'm having an issue that I'm hoping you can help me with.

The script is working fine, but when I try to "sign up" I am not redirected to any pages, and the new user isn't visible in the MySQL database table. I've opened the developer tools inside chrome to try and get a better look, and I'm not getting any console log errors. However, when I open up the network section I get the message "failed to load response data".

In the Sign In page, it says "invalid username or password" but the form asks for email and password. Moreover, when I create an account and log in afterwards, it always says 'invalid usersame or password" What could be the error here? Thanks

In the Sign In page, it says "invalid username or password" but the form asks for email and password. Moreover, when I create an account and log in afterwards, it always says 'invalid usersame or password" What could be the error here? Thanks

It works fine with fastcgi, however doesn't work with suphp it will create a user account, but logging in with it takes you back to the login page without error if the password is correct, or with error if the password is incorrect. The fact that if logging in with the correct password doesn't give an error means it is indeed authenticating, but for some reason stays at login page. Even manually going to the home.php url after logging in kicks you back to the login page.

Thank you for this awesome post. I have a little enquiry. I am creating a volunteer website. assuming I have a table with 10 rows; i.e user_id 1-10. How can I call the details of user_id 1 to show in the dashboard of user_id 2 and the details of user_id 2 to show on the dash board of user_id 1. thanks.