PHP Tutorial: How To Create Login Page in PHP With MySQLi - Alok tv


This website about affiliate marketing keyword research and crome extension tool for wordpress website builder and website theme tutorial

Saturday, July 4, 2020

PHP Tutorial: How To Create Login Page in PHP With MySQLi

PHP Tutorial: How To Create Login Page in PHP With MySQLi

 welcome to day 3 of free course where I will teach you how to create membership system in today video I'm going to show you how to create login system so let me just quickly show you on the table so we will have one page which is login page on this login page we will have email password and login button on the other side here we will have our members area you okay and this is for example just pretty basic page where we say welcome email and this email is what users put here okay so now we need to create some how that not everyone can access this page so only that users are registered can access so once someone press this login button okay inside PHP okay let's see here PHP we are going to check if the informations are correct and if the user with this login details exists in the database if it 

doesn't we will redirect users again to this for okay so all time until user inside correct information he will be resurrected to login page first time, and he inside correct information we will save his data okay and redirect use it to this members area and after that we know that this is registered user and all others are not so pretty much that it now I'm going to show how we are going to do that on the computer so now we know how we are going to create login system let just write the code this time I will write the code a little bit faster since you know all the syntax so let's type in HTML ok form method post ok action is login.php input is text email another one is input this password name is password okay input type submit value log in and name is Log in okay let's now just see in the browser how does it look so but before we go to do that we need to start our XMPP server so here we go this register login PHP here we go let's just that some placeholders okay this is email and this is password test that's it okay now we need to write our PHP code so if is set login so if user pressed this button this code here will execute so first we are going to make connection to our database so it is localhost root password is empty and database is membership system after that we are going to accept this information so it is connection MySQL, no okay and if you remember well we are always doing escape, so we are safe 

from hacking and password is password before we move even further I wanna show you how to encrypt this password so that user so in case that someone login to your database for example like this he in this case he will be able to easy read this password but we want to prevent that so we need somehow encrypt so in my opinion we will just use Sha1 let me show you how does it look so let's just create some empty file for example test.php okay echo let's see okay and this is how our string password will look like so that is very important so when someone open our table he is not able to just read password okay so let me just delete this and edit here we need to do this also on our registration form here okay I already did okay and now let's see if the user with this email and pass encrypted password already exists in our day be so data equal connection query SELECT ID or let's say SELECT first name from users where email equal email AND password equal password ok so if data so in this condition here we are testing how many rows we have in the database so if the number of the rose is bigger than 0 that means that email and password are correct and we are going just to login user so let's say just at the moment echo correct okay and here please take your and you can write any message it just doesn't 

matter okay so let's test this first we are going to insert one user with this encrypt passwords okay and password okay the data has been inserted if we check our database now you can see that this looks much better and the password is not readable with this what we want to achieve so let's go here now login and let's try to login okay and type our okay let me try to type the wrong password one okay please take your inputs and let's now type the correct password say is correct okay and that is it okay so now we know how to check if the data is correct we need to remember our user as logged in so first thing we need to do is at the beginning of this file to both sessions okay and here we are going to save some sessions so let's say email equal email and let's say session logged in equal one okay and if you remember now we are going to redirect user to our members dashboard index.PHP who does put exit here so that the rest of the file will not execute and pretty much that's it fall for the login form now since we want to parent users to be able to see the any page that is not for members we need to create one file that will be at the top of every other file inside members area so for this case we are going to use this Login check PHP and here we are going to type code ok so like this let's say session_start and here we are going to do if here if not is set session email or not is set session logged in we will redirect user 

again to our login.PHP ok next in all other cases user will be successful logged in ok so now we are going to us to include this file inside every file that we want to be protected so let's say that case is for the index PHP so put here just require login check PHP that's it ok and if we do hear something like okay and let's say welcome echo session email this just basic page okay now let's try to access this index PHP since we know that users not logged in already we go here and try okay you can see that every time we are redirected to the late Login PHP but let's not try to Log in sorry okay login in it's says welcome so in this case it doesn't redirect us again to our login page but what if we try to login again and we are already logged in we are able and you want to prevent that so someone who is already logged in we don't want that he login again and again trustee does matter so if isset session email and he isset session no logged in we are just going to redirect him us logged in let's try that now there we go ok so now across all files we know that the user is logged in and he'd just need to log in again and pretty much that's it at the moment for the login system now we are able to login users and later in the future readers I'm going to show you how we are going to create forgot password system and how we are going to create a log out and similar stuff so until the next video bye bye 


Educational Zone said...

This Post Is very Useful Learn English from Hindi daily use english conversation sentences

Educational Zone said...

This Post Is very Useful Learn English of Hindi Daily conversation Sentence

Unknown said...

Relaxtion Music

kashif said...

In this blog I get a great post please also visit my blog I post a great content