Welcome back.
Now, what we need to do is that we need to work on the log in page.
And in order to work on the log in page, the first step is that we need to convert the log in page
from log in that into email to a log in that PDB.
So I'm going to rename the page and I'm going to give it the BGP extension.
I'm going to say logging dot BHP.
So this is the first step.
Now let me go to the log and I'm going to say here for Slash and then log in that be a tree.
And this is the log a bit.
So what we need to do is that we need to take the user from from this log into the account if we if
the log in successfully.
So in the log in Beijing, let me open up the log in page and let's start working on this.
So the first thing is that we need to make sure that the form is, is that we have a form.
So we have a form, as you can see, and we have two inputs.
We have the email and the password and the log in button.
So what we need to do is that here in this form, we need to give it action and method.
So I'm going to say action.
The action is, is going to be log in that the same page and the method is obviously going to be both.
And let's work on the let's work on the logic.
But before we work on the logic, we need to give this button, this input.
We need to give it any.
So I'm going to say your name and the name is going to be log in n log in, underscore median.
Now at the top, we need to add the P because that's going to check and process the log in in this speech.
So here I'm going to say first, I'm going to say include.
Then what we want to include is that we want to include the server server for slash connection.
And then we want to also include this issue.
So I'm going to say at the top, at the very top, I'm going to say session starts because we need to
use the session later and we need to use a statement to check the the pattern.
If the user clicked on the button on the log in button, so I'm going to say a set lost.
And a set Bost log in underscore the end, which is this button, remember this button that I just gave
it a name, log in, underscore between, log in, underscore within, and then you're in this log in.
What we want to do is that we want to get user information, so we need to get the email and the password.
I'm going to say email is equal to.
Fast.
Email.
And the passwords.
Is equal to last.
Password.
And then we need to use the connection in order to connect to the database.
So I'm going to say ACORN and then prepare, prepare.
And then we need to say select.
Select.
Sally.
When do we want to select?
We want to select the the we want to select the user ID and the user the user ID and the user.
Email.
And the username as well.
Being a person username user, underscore name and comma and then user user email.
User user email.
And user password where?
From from first from users.
Where?
From users where?
Where.
User.
Name.
User email.
Is equal.
To question mark and.
And.
Password.
That's.
Use our password.
Is equal to question mark.
And then we need to see a limit.
Limit one when you want only one user.
And then we need to store this in a variable called statement is the empty.
And before we proceed we need to say here in the file we need to hash the password in order to compare
the password with the hash password in the database.
So here we need to say in the file.
And then we want to use this the to bind we need to say and then bind.
Baram.
And then we want to bind the SS email and password email.
And crossword.
And then we need to execute.
We need to say, here is the empty.
Excuse.
This is going to exclude, uh, the the queen.
And then I'm going to hear check.
I'm going to say if.
If the statement is three times true, then here, here we have a result.
Else we don't have a result.
So if this is true, what we want to do is that we need to bind the result, read a statement, and
then bind results.
So what is the what?
What are the what are the values that we want to get from the database?
We want to get the user ID, we want to get the user name and we want to get the user.
Email.
And we want to get the.
User password.
Passport.
And then we need to say Fitch statement, which we need to get to the results.
But before I reach the the result, I'm going to see if if.
If statement if statement num underscore rise is equal to one.
If there's only one user, then we need to fetch.
We need to say a statement which we need to say your statement and then which statement is the empty
and then fetch.
This is going to get a result from the database and we need to store this speech in a in a variable.
It's a raw.
Because this is going to return.
Only one draft to raw is going to be equal to statement which.
And here your air.
Air.
You're there.
There must be an error, and that's it.
Now we want to get the result from.
From the.
From the database.
So we can use this right in order to access the the parameters of these parameters.
Or we can instead, we can use these parameters immediately.
So if we decide to use these parameters immediately, there is no need to store this in or we just need
to say fetch and then we can store.
Now everything in the session, we need a session and then user underscore ID is equal to the ID, the
user ID and then user username.
User username.
Session username.
Session.
User name.
Is equal to user.
Underscore me here, by the way, I should say user underscore name and user underscore name and then
session.
User.
Their score email is equal to user.
Email.
And then.
Session.
Use our password.
We shouldn't be storing the user passwords.
We we we don't need to do this and we shouldn't be doing this, actually.
The last thing that we need to store in this session is the log in status.
And here we need to say logged in.
Logged in is equal to two.
And that's it.
Now, what we want to do is that we want to, um.
To handle EOR.
So here, in case of error, we need to say Heather.
Heather and then location.
Index location log in that BHP and then error is equal to something went wrong.
And here, in case of success, we just need to take the user through the login page to the, to the
account page location.
Location and then account dot BHP.
And here we can see the message is equal to log in successfully.
You can display this message to the user and to hear what they need to do here before I guess they need
to say a statement and then store result, store results.
So that's it to you.
In case of success, we need to do this.
And.
That's it.
Leave me now and let me also display the air so the air can be displayed above the form.
So above the form your B and then style color.
Read.
Glass.
Text Santer here, I'm going to say B2B.
And I'm going to say if is set yet.
If a circuit error.
Then we need to display their.
Echo.
Get air.
Air semicolon.
And regarding the handling of errors here, in case there is not equal to one, then we can also say
else and then we can copy this header and display an error.
And here we can see a log in that BGP and then enter is equal to.
You could not vary by your account or there is no account with these credentials.
And in case of error we need to display here.
Something went wrong.
It also let me add the registration link here.
I'm going to say it is equal to register that BHP alamy go to the log in page to test.
So first of all, I'm going to go to the log in page and refresh and I'm going to here try to log in
with the account that they have created earlier with this account.
So I know my email and password.
Lainey here say info at email dot com.
So if I click on log in, as you can see, I will be taken to my account.
And if I go back to the log in page, let's log in with an email that doesn't exist.
So if they try to log in with this with these credentials, it's going to say, according, to verify
your account is for this part.
And the last thing that we need to do is that we need to prevent the user from going to a login page
if they are logged in.
And to do this, we need to adhere.
So here what I'm going to do is that I'm going to add a statement at the top and then I'm going to say,
session is set.
Session is set.
Session.
Logged in, logged on their score in.
If the user is logged in, then we need to take the user to the account page.
So I'm going to say here, location, either location.
And then I'm going to take the user to the account and then that's it.
We just take the user to that account page and we exit in case the session is set.
Similarly, with the registration page, in order to protect the page completely, we need to, instead
of saying else here, we should actually copy this part and remove it from here and add the elite bracket
here.
Don't forget the cannoli bracket.
And at the top, we need to say.
You're at the top, we need to say.
But if just if if user is logged in, then we take them to the account which lets now this lady notice
this.
So now I should, I should be logged in.
So if I try to go to the login page, I will not be able to.
So if I go to the log in, I will not be able to.
If I try to go to the register, I will not be able to.
As you can see, as you can see, I will not be able to go to the to either the registration page or
the logging page because I'm not logged in.