Soulfire in our cma s and our index page.
We can give you a list of all the articles we can also add a new article and view and edit and delete
existing ones.
However we don't want just any user to be able to do all this as they could at the moment.
We want our index page to be public.
But access to all these other pages should be restricted.
We'll do that by requiring a user to log in first.
First let's create a script that will log the user in Cali luggin appear to be
in here.
Will start resume the session by calling session start.
Then to set whether a user is logged in or not will set a variable in the session array that for now
is just a simple billion that says whether the user is logged in are not.
Lets also add a script that lug the user out and call it like out up here.
Be in here.
Were going to do exactly the same as the luggin script books will set the log in variable to false like
that.
Then in our index page in the body of the astm l..
Lets just print out the contents of the session array.
For now like that.
In the browser we get an error saying that the session is an undefined variable.
This is because we haven't called a session starts in this script.
So if we call it up here like that when we go back to the browser the error has gone and we get an empty
array.
If we open the logon script.
We don't see anything as there's no output on that page but when we go back and refresh the page there's
now a value in the session.
If we open the lock out script.
And then go back.
The value is still there but now it's set to false.
Let's add links to the log in and log out pages here in the index page first.
If a session variable is true then the user is logged in.
If they're logged in then we can add a link to the log out page like that.
If they're not logged in then we'll add a message and a link to the log in page like that.
Let's give that a try.
But note that first I've restarted the browser.
This deletes the current session which will then go about later on.
The first thing that happens when we open the script is we get an undefined index error.
This is because the array exists but this element doesn't exist yet as we haven't called log in.
I'll look out.
So let's add a check here for that.
Like that.
Now we get a message saying were not logged in and the session array is empty but we can click on the
logon link.
And when we go back after being logged in we get the message saying so and we see the value of true
in the session variable.
If I click on the log out link were logged out and when I go back and refresh the page the session variable
is false and it says were not logged in again were locked out.
Now we can see what's happening.
We can remove this vat dump line like that.
So we're basing whether a user is logged in are not on a value in the session which is remembered between
page requests.