In this lecture, you will create a session control mechanism. If the username value in the session
has not been set,
We will kill the page and redirect user to login page.
To do so, we will be using session_destroy(), die() and header() functions.
If you are new to these concepts, please learn more about PHP, session mechanisms and specified functions
before continuing.
So let's start coding.
Open your Atom Editor and create a new file, I will call it session.php and inside
the session.php the first step, you need to start the session.
And for the second step, we will create an if statement to check whether username value in the session
has been set or not.
So let's do so.
If isset session
username.
So if the user name value has not been set in session, we will destroy session and redirect user to
login page.
And we will kill the page by using die() function, we are using it because if the attacker tries to stop
the redirect operation because of the die() function, he won't be able to see the page.
So it's a kind of security mechanism here.
So let's create a new file and call it
index.php and include our session file into it and let's check if our session control mechanism is working
or not by going to localhost slash index.php
As you can see, we have been redirected to login page.
So our session control mechanism is working.
So that is for this lecture.
See you in the next one.