WEBVTT 00:00:07.360 --> 00:00:13.410 All right so far we have compared the tokens we retrieved from the cookie located in the user's device 00:00:13.680 --> 00:00:19.360 with the tokens which are stored in the Remember Me table. 00:00:19.440 --> 00:00:27.290 OK so if people go so much we're going to log the user in and redirect them to the Notes page. 00:00:27.350 --> 00:00:28.170 OK. 00:00:28.230 --> 00:00:29.950 Otherwise we're going to print an error. 00:00:30.240 --> 00:00:31.900 We can start with the error first. 00:00:31.950 --> 00:00:32.540 OK. 00:00:32.550 --> 00:00:41.690 So if the opposites of harsh equals OK we can print an error and then use an else statements. 00:00:42.240 --> 00:00:47.050 OK for logging the user. 00:00:47.650 --> 00:00:48.230 OK. 00:00:48.330 --> 00:00:52.230 Just like this. 00:00:55.290 --> 00:00:58.170 So the error message is going to be something like this 00:00:58.670 --> 00:01:07.970 . 00:01:08.760 --> 00:01:14.670 Hash equals return false for example. 00:01:17.230 --> 00:01:18.810 OK. 00:01:20.760 --> 00:01:27.670 I'm going to use this only for debugging but you can use a general message if you like like remember 00:01:27.670 --> 00:01:28.760 me process failed. 00:01:28.840 --> 00:01:38.690 OK so else means but the hot equals returned true. 00:01:38.840 --> 00:01:47.000 OK so we log in the user in and we are redirecting them to the Notes page but before we do that we're 00:01:47.010 --> 00:01:49.800 going to regenerate new tokens. 00:01:49.830 --> 00:01:50.690 OK. 00:01:51.030 --> 00:01:57.210 So that's going to be done just before logging the usery. 00:01:58.630 --> 00:02:05.100 OK so you're going to generate then store them in the cookie and in the table again and then we're going 00:02:05.100 --> 00:02:12.220 to log the user in and redirect them to the Notes page. 00:02:13.920 --> 00:02:20.260 So to regenerate these tokens we're going to use exactly the same code we used in the logging file. 00:02:20.600 --> 00:02:23.220 OK. 00:02:26.430 --> 00:02:33.060 So we're going to stop right there because the success message that we used in the log file is specific 00:02:33.270 --> 00:02:36.030 to the logging outputs. 00:02:36.100 --> 00:02:45.110 OK so let's copy this code and paste it right there. 00:02:46.250 --> 00:02:51.370 OK. 00:02:55.770 --> 00:02:56.450 All right. 00:02:56.460 --> 00:03:05.520 Now after logging the user in with me to redirect them to the Notes page so to do that we're going to 00:03:05.520 --> 00:03:08.030 use the header function. 00:03:09.610 --> 00:03:11.590 OK. 00:03:13.440 --> 00:03:17.330 And the file going to be redirected to is 00:03:21.000 --> 00:03:28.070 main page located in both BHB. 00:03:28.300 --> 00:03:28.560 OK 00:03:28.570 --> 00:03:34.860 . 00:03:36.170 --> 00:03:36.860 All right. 00:03:36.870 --> 00:03:40.300 Now let's have a quick look at our code before we test it. 00:03:40.590 --> 00:03:46.200 So in our first IF statements you've got two conditions there. 00:03:46.260 --> 00:03:49.090 So you got condition 1 and condition 2. 00:03:49.140 --> 00:03:52.490 So we need to use two ampersands that all. 00:03:52.620 --> 00:03:53.680 And. 00:03:54.160 --> 00:03:56.370 OK. 00:03:56.560 --> 00:03:57.230 OK. 00:03:57.450 --> 00:04:07.320 And if you look at the first problem instead of the house equals function. 00:04:07.340 --> 00:04:14.260 So the first barometer is the elements inside the row array. 00:04:14.400 --> 00:04:17.450 OK. 00:04:17.470 --> 00:04:20.580 Of index to all and to vacated to. 00:04:20.580 --> 00:04:27.600 So the brackets should and right there rather than that. 00:04:28.200 --> 00:04:36.370 All right now to Teso code we're going to use Internet Explorer as if you close the window. 00:04:36.420 --> 00:04:40.940 Google Chrome OK you might not be able to destroy the session. 00:04:41.160 --> 00:04:42.590 OK. 00:04:42.600 --> 00:04:47.020 As Chrome will usually keep running in the background. 00:04:47.040 --> 00:04:51.510 OK so I'm going to use Internet Explorer to log in first 00:05:07.420 --> 00:05:13.640 I'm going to check the Remember Me Books. 00:05:13.890 --> 00:05:21.290 Now I'm going to destroy the session by closing the Internet Explorer window like this. 00:05:21.780 --> 00:05:22.820 And now let's open 00:05:27.560 --> 00:05:28.700 Internet Explorer again 00:05:31.590 --> 00:05:33.740 and go to the homepage 00:05:33.760 --> 00:05:40.090 . 00:05:47.270 --> 00:05:53.880 So we were expected to be redirected to the Notes page but for some reason this hasn't happened. 00:05:53.960 --> 00:05:54.590 OK. 00:05:54.710 --> 00:06:02.090 So again for many browsers if you close the browser the session is not necessarily going to be destroyed 00:06:02.110 --> 00:06:02.230 . 00:06:02.330 --> 00:06:06.410 OK so now let's check if actually hour session has been destroyed or not. 00:06:06.410 --> 00:06:07.220 So what are we going to do. 00:06:07.220 --> 00:06:09.270 We're going to go to our code. 00:06:09.410 --> 00:06:17.420 So if you remember of course our IF statements are rewriting all these code for these two conditions 00:06:17.440 --> 00:06:17.490 . 00:06:17.540 --> 00:06:18.120 OK. 00:06:18.230 --> 00:06:19.480 If they are fulfilled. 00:06:19.640 --> 00:06:33.130 Now if the conditions are not fulfilled or one of them is not then we're going to echo a message. 00:06:33.200 --> 00:06:33.760 OK. 00:06:34.160 --> 00:06:35.710 So let's make this easy. 00:06:36.140 --> 00:06:39.290 I'm going to copy that message. 00:06:39.440 --> 00:06:47.850 So first I'm going to echo a message where we can show the session user ID. 00:06:48.080 --> 00:06:49.300 OK. 00:06:50.360 --> 00:06:50.950 All right 00:06:51.040 --> 00:07:02.990 . 00:07:12.470 --> 00:07:12.950 OK. 00:07:12.950 --> 00:07:16.410 And also I'm going to echo another message. 00:07:16.660 --> 00:07:19.760 OK showing the cookie value 00:07:19.760 --> 00:07:30.780 . 00:07:30.780 --> 00:07:32.220 All right. 00:07:33.440 --> 00:07:33.680 OK. 00:07:33.680 --> 00:07:43.930 Now let's say and go back to our home page and refresh before we go that's legis. 00:07:44.060 --> 00:07:46.490 Some Margene top to the first Dave. 00:07:46.590 --> 00:07:52.580 OK so that we can see that Dave doesn't overlap with the navigation bar. 00:07:52.790 --> 00:07:55.730 So let's add some styling. 00:07:56.160 --> 00:08:02.540 Right the style was munching. 00:08:03.390 --> 00:08:05.610 So 50 50 pixel. 00:08:05.620 --> 00:08:06.660 For example. 00:08:07.070 --> 00:08:10.040 OK so let's refresh the page. 00:08:10.760 --> 00:08:11.310 OK. 00:08:11.510 --> 00:08:16.980 And now we can see our user ID is 11 and the cookie value we can see that. 00:08:17.390 --> 00:08:23.450 And now we understand that the session hasn't been destroyed as we can still see our user ID. 00:08:23.450 --> 00:08:29.390 Now I'm going to close all browsers and try again. 00:08:31.730 --> 00:08:39.070 OK so let's open Internet Explorer again and let's go to our Web sites. 00:08:40.340 --> 00:08:40.780 OK. 00:08:41.000 --> 00:08:44.630 So now the session has actually been destroyed. 00:08:44.810 --> 00:08:45.440 OK. 00:08:45.620 --> 00:08:53.050 And we getting an error in line 27 of the remember file. 00:08:53.240 --> 00:08:54.190 OK. 00:08:54.230 --> 00:09:00.200 And the reason why is because of the harsh equals function. 00:09:00.260 --> 00:09:10.280 So since we got to that line that's means that's the condition of our IF statements is fulfilled. 00:09:10.400 --> 00:09:11.130 OK. 00:09:11.450 --> 00:09:15.260 So we don't have a user ID and we do have a cookie. 00:09:15.470 --> 00:09:23.990 Now the reason why we see this error is because the function Hosh equals will only work with BHP version 00:09:23.990 --> 00:09:26.640 5.6 and above. 00:09:26.670 --> 00:09:31.660 Ok so you get a need to change the PSP version that we we're working with. 00:09:31.670 --> 00:09:43.590 OK now let's open chrome again and let's go to our panel and check was BHB version. 00:09:43.940 --> 00:09:47.140 We have at the moment. 00:09:48.980 --> 00:09:51.710 OK. 00:09:54.600 --> 00:09:57.530 So of course version five point four. 00:09:57.680 --> 00:10:01.170 Let's go for 5.6 now. 00:10:01.790 --> 00:10:03.340 OK. 00:10:04.570 --> 00:10:06.880 We're going to save straightaway. 00:10:08.030 --> 00:10:08.870 OK. 00:10:09.380 --> 00:10:12.420 Now let's try again. 00:10:21.480 --> 00:10:27.010 OK so if we go back and click on set as current. 00:10:28.340 --> 00:10:28.770 OK 00:10:31.680 --> 00:10:35.840 now let's try again. 00:10:38.330 --> 00:10:38.820 OK. 00:10:38.840 --> 00:10:42.770 Now it works and we've been redirected to the Notes page. 00:10:42.780 --> 00:10:43.990 OK. 00:10:44.310 --> 00:10:47.160 Right now is go back to our code and 00:10:50.580 --> 00:10:53.770 deletes the else statements we added at the end. 00:10:54.070 --> 00:10:54.630 OK. 00:10:55.010 --> 00:11:01.990 We all need that's going to save. 00:11:02.120 --> 00:11:08.040 Right now our user is going to be remembered for 15 days unless they logout. 00:11:08.100 --> 00:11:13.520 OK so what are we going to do now we're going to build the Lugo's process quickly. 00:11:13.590 --> 00:11:18.370 So we need to go back to the sign up the index does BHB file. 00:11:18.530 --> 00:11:19.810 OK. 00:11:20.900 --> 00:11:23.920 And add some code just before the Remember Me code. 00:11:23.990 --> 00:11:24.520 OK. 00:11:24.730 --> 00:11:29.220 So this is a common they're saying logout. 00:11:29.250 --> 00:11:29.870 OK. 00:11:30.030 --> 00:11:39.690 So rather than writing code straight here we can create a file Lugo's does BHB and just include this 00:11:39.690 --> 00:11:45.130 file in our index those page people OK 00:11:48.120 --> 00:11:54.260 that makes our code structure a lot more readable. 00:11:54.310 --> 00:12:00.930 OK so now let's go to a.p and create this file 00:12:02.840 --> 00:12:04.680 . 00:12:04.860 --> 00:12:05.690 Those BHB 00:12:08.340 --> 00:12:10.010 . 00:12:10.750 --> 00:12:16.570 And let's open it using rockets. 00:12:18.840 --> 00:12:19.140 OK 00:12:22.250 --> 00:12:27.690 so now what are we going to do when they use that goes to the notes page and they'd like to look out 00:12:27.700 --> 00:12:27.930 there. 00:12:27.990 --> 00:12:31.240 They're going to click on the logout link. 00:12:31.350 --> 00:12:36.780 So once they click on the logout link the he's going to send them to the index. 00:12:36.860 --> 00:12:42.950 Those PSP file OK with a gets barometer. 00:12:43.020 --> 00:12:55.530 So once we get there OK the Gets barometer is going to be caught by the logos. 00:12:55.560 --> 00:12:56.950 Those pieces fall. 00:12:57.570 --> 00:12:58.640 OK. 00:12:59.310 --> 00:13:05.620 And then we're going to lock the user out by destroying the session. 00:13:06.030 --> 00:13:08.780 OK so let's go to the main page. 00:13:08.970 --> 00:13:11.060 Locked in. 00:13:11.880 --> 00:13:15.180 Going to open that page to see the link 00:13:20.620 --> 00:13:25.540 and this look for the logout link. 00:13:26.520 --> 00:13:28.750 OK so here it is. 00:13:30.090 --> 00:13:37.310 So the ATF of this link is going to be our index those file. 00:13:37.380 --> 00:13:38.730 All right. 00:13:39.830 --> 00:13:43.750 But we're going to OD A gets. 00:13:46.050 --> 00:13:46.860 OK. 00:13:46.970 --> 00:13:51.440 You're going to call logout and we're going to say about barometer to one. 00:13:51.450 --> 00:14:01.110 All right so let's save this and let's go to our index those BHB file. 00:14:01.130 --> 00:14:04.970 So these files are going to receive the promiser OK through the logos. 00:14:04.960 --> 00:14:09.280 Does the file go there and write some code. 00:14:10.080 --> 00:14:13.380 So first of all we're going to check if the user is logged in. 00:14:13.400 --> 00:14:14.660 OK. 00:14:14.730 --> 00:14:22.940 And also if we do get all we do we do have a logout barometer equal to 1. 00:14:23.150 --> 00:14:23.400 OK. 00:14:23.390 --> 00:14:28.220 So the code is going to be as following. 00:14:29.120 --> 00:14:35.790 So first we're going to have an if statement if the user is logged in. 00:14:35.790 --> 00:14:43.150 That means that we've caught the second user ID for example is set. 00:14:43.380 --> 00:14:45.160 OK. 00:14:46.350 --> 00:14:47.220 OK. 00:14:47.540 --> 00:14:49.640 And we've got 00:14:57.310 --> 00:15:02.730 Also we go into check that we did receive the promiser logout. 00:15:02.750 --> 00:15:03.390 OK. 00:15:03.730 --> 00:15:07.990 Which is going to be inside the 00:15:11.500 --> 00:15:13.190 get array. 00:15:13.260 --> 00:15:17.620 OK. 00:15:20.440 --> 00:15:28.310 And I want to make sure that's this elements is equal to one. 00:15:30.550 --> 00:15:38.120 Then you either place and like this all to ampersands just like this. 00:15:38.620 --> 00:15:39.960 OK. 00:15:40.000 --> 00:15:41.440 All right. 00:15:41.620 --> 00:15:46.780 Now if these two conditions are fulfilled we're going to destroy the second. 00:15:46.840 --> 00:15:51.730 We're going to use the function session and the school destroy. 00:15:52.960 --> 00:15:58.360 OK so this function is going to destroy the session and all the session variables. 00:15:58.380 --> 00:16:03.900 Also if the user logs out they're not going to be remembered anymore. 00:16:04.080 --> 00:16:07.270 OK so we don't need to destroy the Remember Me cookie. 00:16:07.540 --> 00:16:12.370 So to destroy the cookie you can use the same function used to create the cookie. 00:16:12.500 --> 00:16:14.590 OK but this time 00:16:17.920 --> 00:16:24.190 the first parameter is still going to be the name of the cookie in question which is remember. 00:16:25.710 --> 00:16:27.210 OK. 00:16:27.850 --> 00:16:29.430 But the value of the cookie. 00:16:29.640 --> 00:16:37.170 OK you can give it's an empty value like this with the expiration parameter. 00:16:37.240 --> 00:16:40.290 You would need to give something in the past. 00:16:40.300 --> 00:16:45.210 So an example of this could be the current time. 00:16:45.310 --> 00:16:48.830 OK using the Unix time stamp mine is something. 00:16:49.030 --> 00:16:53.300 So we know there's going to be something in the past. 00:16:53.440 --> 00:16:59.550 So I would go for minus 3600 for example which is the current time minus one hour. 00:17:00.120 --> 00:17:00.420 All right. 00:17:00.430 --> 00:17:04.050 Now let's test our code and make sure everything is working. 00:17:04.240 --> 00:17:18.310 So let's refresh the notes page and then click on logout and then we can see that's we've been logged 00:17:18.310 --> 00:17:18.780 out. 00:17:18.840 --> 00:17:22.750 OK but now you will see that there is a problem. 00:17:22.890 --> 00:17:30.720 If you go to the previous page even though you've been logged out you're still able to access the notes 00:17:30.720 --> 00:17:31.440 page. 00:17:31.780 --> 00:17:32.590 OK. 00:17:32.590 --> 00:17:39.240 So we're going to need to avoid this by modifying the code in the PSP file. 00:17:39.280 --> 00:17:41.020 So what are we going to do. 00:17:41.050 --> 00:17:45.040 We're going to go back to the news page and at the top of the page 00:17:49.060 --> 00:17:54.130 we're going to write a couple of lines. 00:17:54.450 --> 00:17:55.590 OK. 00:17:56.530 --> 00:18:02.910 So we're going to check if there is no session or if the user is not logged in. 00:18:02.910 --> 00:18:08.030 If that's the case we're going to redirect the user straight to the Help page. 00:18:08.050 --> 00:18:08.740 OK. 00:18:08.740 --> 00:18:18.370 So we're going to have an assessment on the condition he's going to be if a session variable is not 00:18:18.420 --> 00:18:19.070 set. 00:18:19.240 --> 00:18:20.100 OK. 00:18:20.100 --> 00:18:25.970 So we're going to use the function is set all the opposites like that's. 00:18:26.260 --> 00:18:34.800 And let's go for the user id elements inside our session. 00:18:38.140 --> 00:18:39.570 OK. 00:18:40.410 --> 00:18:51.220 So if that's the case we're going to redirect the user using the header function like this to the index 00:18:51.350 --> 00:18:51.740 . 00:18:51.910 --> 00:19:00.330 Those people and very importance before we move ahead since we're working with session variables we'd 00:19:00.340 --> 00:19:04.230 need to start or restart the session at the top of the file. 00:19:04.510 --> 00:19:07.540 Ok that's very important. 00:19:08.660 --> 00:19:09.320 OK. 00:19:10.170 --> 00:19:15.390 So now let's save and refresh the page. 00:19:16.600 --> 00:19:23.050 So we've been redirected to the home page because there is no second variable user ID. 00:19:23.160 --> 00:19:23.770 OK. 00:19:23.770 --> 00:19:27.510 Now let's logon. 00:19:30.250 --> 00:19:31.320 OK. 00:19:31.600 --> 00:19:39.850 Now let's logout and let's try to go to the previous page. 00:19:40.220 --> 00:19:45.950 Now you can see that we've been redirected to the home page because the session has been destroyed. 00:19:46.060 --> 00:19:47.190 OK. 00:19:47.970 --> 00:19:48.200 All right. 00:19:48.220 --> 00:19:56.730 In the next video we're going to write code for the forgoes password feature.