Allowing the user to log in by simply clicking on a link like this isn't really worth doing as anyone
could do it.
When a user logs in we need to get some credentials from them which usually consists of a username and
password.
So here in our logging script let's remove this code for now and add a log in from We'll start with
our standard 8 2 email header and footer and then add a title next.
We need a form which will process in the same script so we don't need an action attribute.
Then we need the label and input for the user name which is a simple text input and also a label and
input for the password which is a password type input.
Finally let's add a button to submit the farm
in the browser.
Here's the farm and we can enter a username and password and submit the farm.
However the username and password I typed in have appeared in the address bar of the browser revealing
the password.
In addition to being visible here this u are l will be saved in the browser's history which anyone with
access to this computer could see.
Not what we want.
This is because we haven't specified the post method in the farm.
It's using the get method by default.
So let's add to that like that.
So when the farm is submitted we can detect this as before and we can check the user's credentials from
the value submitted on the farm.
For now let's just check that they match a hard coded username and password.
And if they do we'll print out one message and stop the script otherwise we'll print out a different
message.
So now if I enter the correct credentials and then submit the farm we get one message and note that
we no longer see the user name and password in the address bar.
If I enter incorrect credentials and we submit the farm we get the other message.
So if we log in correctly we want to set the value in the session as we did before and after that Let's
redirect back to the index page.
We can do this using the redirect function we created earlier.
And don't forget so we can use this.
We need to include the file where that redirect function is.
So will do this here at the top.
If the log in is incorrect Lets put this error message in a variable
and then in the 8 Tim and below.
If this variable isn't empty will print the message out like that.
So now if I try and log in and I enter incorrect credentials we get there a message.
If I enter correct credentials and submit the farm were redirected to the index page and the message
says were logged in.
So the value has been correctly set in the session and we've been logged in successfully.