Login form using session and cookie with remember me in php

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends I am Dugas Ani and we are creating series of video tutorials for super global variables in PHP so in in previous tutorials we have seen about cookies and sessions so using these cookies and sessions we are going to create a login form which will authenticate a user with valid credentials and if him preys on remember me if he check this button red check box and click on login button under time when the next time he comes to the same page so we should populate its username and password so he may live in password no need to enter again username and password same concept like Gmail or Facebook so the same concept we are going to implement in PHP so let's see how it work so here what I have did I have created one form login dot PHP and in that form I have created a email email filled with name email then password then we have checkbox and one button submit button and little bit of 40 formatting so this is how it looked like my page is look like this so whenever user click on this button it will go on where a dot PHP will validate the user so we will see how it worked so let's start so we know that when user click on login button so this name is login here we'll check one condition if each said dollar underscore post locking if login button is hit then only go inside okay so as you can see I am using method post and sending it will be the where the dot PHP so method is good that is why I am using dollar and has composed so if it is then or is will show on validation message are we sending again into the login page so there is one function header and in the header section we have one parameter location with the help of that location we can send it to again login dot PHP file that's it so if that if anybody want to except this file directly so it will not allow him like see if I am trying to open while you did dot PHP this one so what we have is semicolon we have missed here refresh see if I am trying to go to this file valid under PHP again it is redirecting me to here only when we click on this button then only it will go inside this if go okay so let's perform the further operations so we know that we are going to get email even is equal to dollar underscore post method and the name of that field is email only so we get the email then what we want we want to password password is equal to dollar underscore post and we want password we get the passer from this field then one more field we want dollar remember is equal to dollar underscore post and I guess it's name is remember will see will cross verify once again so it's name is remember only okay so we'll get these values also but see we are getting these two values and as I do not have any database so what I will do I will create a static very static variable if you have a database so you can fit these two values from database also so I am using here I'm changing the name my email my email is equal to writing are Doosan even add the red yahoo.com okay and I'm using my password pass is equal to one two three four five like this okay so suppose suppose this is my dummy username and this is my password so these two information if user send these two information then only we are going to validate it otherwise we'll throw an error so what we'll do and if remember we remember is said then what we will do will create a cookie for the same so let us see how to do this so if I I'll inject first if the email which came this email is equal to my email okay and Pass is equal to is equal to my pass in both are correct then only will allow and go further otherwise we'll throw an error so what we will say Eko here we do email our password is invalid like this we can do and one more thing we can do here we are click here to try again and what we can do try and here we can use anchor tag HRP M is equal to login dot PHP and we can close it like this so see we are going here again go back pick fresh and clean here I am not providing the username and password so here what we are getting email or password is incorrect click here to try again so it will go again to the login page like this we can implement and if it is provided then what we will do again we'll check on condition if this is correct okay then only here we access this value and we'll use send cookie and in the same cookie will write email comma that value what he has written email and value use time function will add our limit up to 60 second 60 minute and maybe 10 days or seven days okay so it will be valid for seven days then we are creating this cookies we'll check one condition if we'll take one condition Eve is said this value is said then only we will do this otherwise we are not going to create this cookie so we'll check on condition and you can remove this one if it is there they only create this thing otherwise no need to create it just close it opening closing we have set cookies and if everything is okay then what we will route we'll send it to the header welcome dot PHP with sending location welcome dot php' somewhere like this so we create this file copy and these opening everything is more since good create a new file PHP to save it with this name welcome dot PHP and here what we are going to do what we will do will create a session as well as we want to access these values into the next page so we'll create a session also so if everything is okay so here what we will do we use session underscore start function okay and we will set one variable dollar underscore session email is equal to dollar email this value we'll set it here and then let it go to the next page welcome so if it will come here so what we have to do will check one can we will start first session here and we'll access that value this period will access this field and show the message welcome something eco here will say welcome and that email ID whatever the humor ID is so like this ratio and we will give a link Eco give one button called logout if you want to log out so we provide a link here so we'll do it later I will show you let's see it's working or not just refresh this webpage provide the incorrect values whatever like a PC at the rate gmail.com like this if you are providing and provide the values with anything click on login so here what you are getting email or password is incorrect so now enter the correct values now this email and this value is pass 4 1 2 3 4 5 click on login button so now what happened ok we have one thing we have to do actually remove this thing from here place it outside this function this condition because we want to create a cookie only when the remember when we are checking this when we are checking this then only we want that thing otherwise known you so we should write this this code outside the block let's see now rephrase this webpage provide the correct values and password and remember me okay don't don't remember me right now click on login so you are going to the Welcome dot PHP and you are getting welcome these values now we want to show here or we want to show logout button here okay so what we can do Iko and a href is equal to Lago dot php' this file we need to create and here closing anchor tag that's it okay so just create a new file save it with logout dot PHP love of darkness me save this file okay and in this file what we are going to do PHP it is fine and session underscore destroy and we show a message you cool logo and so we can show this message here somewhere click here too login again like this weekend or better is confirmed the studio login again okay simply save this file now we are done we'll stay we are done we have clear the first thing the phrase is work page and you will see logout button so whenever you click on this page you will see you successfully log out click here to log in again so see now this time our we didn't if you are providing the current values see you're probably the correct value one two three four five and not checking it click on login you are going to the correct file ok then everything is correct and now we are providing the correct value one two three four five and when you change this button this check box and click on login now this time if you go to the browser settings you will see that we have created on cookie also cookie and you will see here we have created one cookie email so we are storing email here successfully but with the help of email along with the email we have to save password as well so here what I'm going to do dollar underscore sorry not here here along with the email ID will save the password actually we are not doing like this I am just demonstrating how to use this we have two we are not showing credentials here in in to the cookies but you can encrypt it or you can use any algorithm to encrypt this file this username and password and you can then store it into the cookies but it is not right way to store it into the cookies into the client-side so I am just demonstrating how to how you can use these concepts okay so here I am using pass now it will it will also get stored there so these two information I have saved and in the first file login page we will check one condition here somewhere top will check on condition PHP and we'll do one thing we'll check is there any cookies with this none this name so as we know that there is one super global variable cookie cookie and bill check is any value with sorry not name with email and dollar and here we'll save it into a variable dollar email is equal to this and pass is equal to dollar underscore cookie with parse if we are getting this value then what we have to do and we can validate it it with if it said this and it said this then only go inside and check these things okay so if you are getting these things things so what we need to do we have to show these values into this particular text box so we are going to use little JavaScript eco script opening and script closing bag here then what we need to do we have to access these values these controls so I am going to use IP here and we'll give the IT email only and here also ID with pass so here what we will do we will call document dot get element by ID method and we'll pass the ID email dot value is equal to that we have dollar email like this maybe but okay we'll see it's working or not otherwise we have to pitch it near pass which is working or not as we have created this type go back refresh this webpage greetings semicolon we are power 10 so I am going to correcta morality by this one login we have successfully logged logged in and if you go here you will find that now there are two bookies email and password where these two things and if you are going again to the login page go to the login page again so it should come here and show this values eco email are we getting this value yes we are getting this value and we are getting this value then we are a large dollar email are you getting this value they will test you for some time are you getting this value here yeah now we are getting this value so the same thing we have to do email and bus there see what happening console you can see that console and again the fish we are getting error here so cannot sell property value of none okay okay so what we will do just copy this code and paste it below I will tell you why we were getting the error see refresh this webpage now you will get to the user okay so here we are getting the email and here we are going to be passed a password also so why we were getting this error because it was interpreting first and it were trying to face them this email email field but this idea was not it was good previously as we are trying to here only so this period is here so we should use these concepts we know this poor as this all the documents are get generated on the documents on HTML so easily it will access here it will find the email and password and it will assign the correct values so see if user was these things so it automatically will get the values and whenever one more thing we have forward here actually we should destroy the cookies also so how to destroy the cookies I will show here I will copy these two things and I paste it here and what we will do we will - is it by one - one that's it it will delete the cookie also let's go now our full function code is ready so I am going to login logout undefined variable email and password okay so email instead of email what we came to we will use this concept here also Coffee distant mr. together now we have email and passport the things so it will go here and same condition we have to check here also otherwise we get error so we'll validate that thing also if there is if there is this thing these things are said then only try to delete these things then only try to delete these two keys and all and closing we are done refresh now we are not getting any error okay so now the book there is no booking if you go here and try to check only one cookie is there so I am removing everything now we do not have any cookie go again here click on this and we have entered the correct username and wrong password click on login we are getting error if we have entered a correct username and current password click on remember button click on login we are getting to the going to the Welcome dot PHP which is correct and if you see here so we also have the cookies email and password email and pass or all the things then again if you are going if suppose you you have close these tabs and if you are opening it again login fine see if you're opening it login file the islami login dot PHP as you can see here we already have these informations username and password no need to write it again click on login button you are in that's it logout now if you go to the login button again you will not get these values so this is the very simple concepts how to achieve this goal remember my concepts in PHP so will revise first once again here what we have done we have created one form a form method is post and we are sending into the welder or PHP we have a email field we have a password field then we have a remember we checkbox then we have submit button and what we are doing we are sending it to validate if this submit button is clicked then then only go inside and take the username and password and if it is matching with this username and this password then only go inside and if user has selected checkbox then create a Pookie's as if it is not check these things you know this concept and Gosai a further and create a session and we are assigning the session variable here to access this value for the I use like welcome dot PHP and if suppose is not hit the and suppose the you you are in password is username and email and password is incorrect then show this validation message and if you are not click somebody wants to directly come to the this file so again go say name to login dot PHP then in here just we are showing the Welcome message and logout button in logon we are destroying the cookies and destroying the sessions also yeah and if the person has check the Remember Me button so we are checking if the cookies is created for even password we are taking it and we are just doing it with with the jail JavaScript to showing the value to the particular controls so this is a very simple example of creating a login form with the help of session and cookies and maybe in the further videos I will create the login form are very some more enhancement like with database concepts and all so I hope you guys understand the concept of session in cookies and if you like my videos please subscribe my channel thank you very much for watching you
Info
Channel: learnWebCoding
Views: 229,960
Rating: undefined out of 5
Keywords: PHP, MySQL, AJAX, JQUERY, JavaScript, login, session, cookie, session and cookie, Login using session and cookie with remember me in php, remember me in php, login form in php, login form in php and mysql
Id: 3jfBOD5Mw0Q
Channel Id: undefined
Length: 31min 19sec (1879 seconds)
Published: Tue Mar 15 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.