1 00:00:00,670 --> 00:00:07,870 In this lecture, you will create a session control mechanism. If the username value in the session 2 00:00:08,140 --> 00:00:09,410 has not been set, 3 00:00:09,910 --> 00:00:13,430 We will kill the page and redirect user to login page. 4 00:00:14,200 --> 00:00:19,930 To do so, we will be using session_destroy(), die() and header() functions. 5 00:00:20,660 --> 00:00:28,270 If you are new to these concepts, please learn more about PHP, session mechanisms and specified functions 6 00:00:28,570 --> 00:00:29,770 before continuing. 7 00:00:30,970 --> 00:00:33,610 So let's start coding. 8 00:00:35,410 --> 00:00:45,880 Open your Atom Editor and create a new file, I will call it session.php and inside 9 00:00:45,880 --> 00:00:51,910 the session.php the first step, you need to start the session. 10 00:00:54,010 --> 00:01:01,510 And for the second step, we will create an if statement to check whether username value in the session 11 00:01:01,690 --> 00:01:03,210 has been set or not. 12 00:01:04,000 --> 00:01:05,980 So let's do so. 13 00:01:08,770 --> 00:01:12,760 If isset session 14 00:01:15,790 --> 00:01:16,300 username. 15 00:01:17,450 --> 00:01:35,480 So if the user name value has not been set in session, we will destroy session and redirect user to 16 00:01:35,630 --> 00:01:36,440 login page. 17 00:01:45,390 --> 00:01:57,900 And we will kill the page by using die() function, we are using it because if the attacker tries to stop 18 00:01:57,900 --> 00:02:04,310 the redirect operation because of the die() function, he won't be able to see the page. 19 00:02:04,590 --> 00:02:08,330 So it's a kind of security mechanism here. 20 00:02:11,680 --> 00:02:14,590 So let's create a new file and call it 21 00:02:17,290 --> 00:02:30,940 index.php and include our session file into it and let's check if our session control mechanism is working 22 00:02:30,940 --> 00:02:35,710 or not by going to localhost slash index.php 23 00:02:36,490 --> 00:02:42,480 As you can see, we have been redirected to login page. 24 00:02:42,610 --> 00:02:47,460 So our session control mechanism is working. 25 00:02:48,250 --> 00:02:50,220 So that is for this lecture. 26 00:02:50,500 --> 00:02:51,540 See you in the next one.