WEBVTT 00:00:07.170 --> 00:00:07.530 All right. 00:00:07.530 --> 00:00:13.920 Now let's test our code and make sure that the user is remembered if they check the box while logging 00:00:13.920 --> 00:00:14.240 in. 00:00:14.410 --> 00:00:15.780 OK so it's log in 00:00:20.020 --> 00:00:22.890 and check the box OK. 00:00:23.040 --> 00:00:25.050 So we're going to log in now. 00:00:25.950 --> 00:00:29.060 So we're redirected to the Notes page. 00:00:29.130 --> 00:00:36.900 OK now we're locked in now is check the remember table and make sure that we've got a record added to 00:00:36.900 --> 00:00:42.740 the table which means that we're going to be remembered for the next time we try to log in. 00:00:42.770 --> 00:00:43.560 OK. 00:00:44.070 --> 00:00:51.200 So it is click on the remember table and see how many records you've got there so you can get one record 00:00:51.210 --> 00:00:54.150 there we can see our first run of variable. 00:00:54.250 --> 00:00:55.550 And the second one. 00:00:55.560 --> 00:01:00.230 OK husht OK and you can see the expiry date on time that. 00:01:00.600 --> 00:01:01.220 All right. 00:01:01.290 --> 00:01:04.210 So our code is working fine. 00:01:05.670 --> 00:01:13.200 Now when the user comes back to the website given that they haven't looked out OK and that their session 00:01:13.260 --> 00:01:19.820 has been destroyed then they should be remembered if they check the box while logging in. 00:01:20.000 --> 00:01:21.150 OK. 00:01:21.180 --> 00:01:29.640 So first we're going to go to the top of our index file which is our home page and we can write some 00:01:30.150 --> 00:01:31.110 code there. 00:01:31.330 --> 00:01:33.320 OK. 00:01:33.700 --> 00:01:38.320 Saying if the user is remembered then they're going to be logged in. 00:01:38.490 --> 00:01:40.020 OK. 00:01:41.580 --> 00:01:44.490 So first we need to start a session. 00:01:44.670 --> 00:01:45.010 OK 00:01:45.010 --> 00:01:51.400 . 00:01:53.400 --> 00:01:59.910 Using the session starts a function. 00:02:05.280 --> 00:02:05.770 OK. 00:02:05.790 --> 00:02:13.620 Also we're going to connect to the database as we're going to be running some queries later on. 00:02:13.700 --> 00:02:13.970 OK. 00:02:13.980 --> 00:02:21.110 So we are going to include our connection File for us. 00:02:25.720 --> 00:02:30.510 Okay then we're going to write our remember me code. 00:02:30.570 --> 00:02:35.010 Ok so to keep our code tidy. 00:02:35.070 --> 00:02:42.950 Easy to read We're going to place our code inside our remember me file. 00:02:43.050 --> 00:02:44.500 Ok which we created there. 00:02:44.760 --> 00:02:52.020 So we're just going to refer to that file using the include function. 00:02:55.190 --> 00:02:56.580 OK. 00:02:57.390 --> 00:03:02.230 Save the file is called remember was Page B. 00:03:02.790 --> 00:03:08.170 Ok so now let's go to the file and start writing code there. 00:03:08.510 --> 00:03:14.370 I'm just going to pause and tidy up these comments greatly as they look like HMO comments now. 00:03:14.480 --> 00:03:15.400 OK. 00:03:15.950 --> 00:03:17.210 OK that looks better. 00:03:17.220 --> 00:03:22.410 So the first thing we're going to do is to check that the user is not locked in. 00:03:22.410 --> 00:03:23.030 OK. 00:03:23.040 --> 00:03:25.570 And also that they have a cookie on their device. 00:03:25.650 --> 00:03:26.240 OK. 00:03:26.310 --> 00:03:27.620 Remember me cookie. 00:03:27.840 --> 00:03:32.100 So to do this when to use an IF statements. 00:03:32.100 --> 00:03:32.750 OK. 00:03:32.970 --> 00:03:39.870 So the condition we're looking for first is that the user is locked in and we can check that by looking 00:03:39.960 --> 00:03:42.080 at the session variable. 00:03:42.150 --> 00:03:43.170 OK. 00:03:43.890 --> 00:03:45.490 Or the session array. 00:03:45.510 --> 00:03:50.400 So we're going to check the elements corresponding to the user ID for example in our stationery. 00:03:50.850 --> 00:03:56.160 So we going to check that's the elements 00:03:59.700 --> 00:04:03.090 user ID inside our session array 00:04:08.040 --> 00:04:10.350 does not exist or is not set. 00:04:10.350 --> 00:04:10.870 OK. 00:04:10.940 --> 00:04:14.760 So to do this we can use the function is set. 00:04:14.940 --> 00:04:15.240 OK 00:04:16.530 --> 00:04:20.610 . 00:04:20.650 --> 00:04:23.960 We going to use the opposite of the result. 00:04:24.270 --> 00:04:25.470 OK. 00:04:26.480 --> 00:04:30.030 There is also another way of doing this if you work in with an array. 00:04:30.030 --> 00:04:36.530 There is a function called array and the call he exists. 00:04:36.600 --> 00:04:42.000 Ok so this function takes a couple of promises so the first one is the key element that you're looking 00:04:42.000 --> 00:04:42.350 for. 00:04:42.360 --> 00:04:47.410 In our case user ID and the second barometer is the array. 00:04:47.930 --> 00:04:48.430 OK. 00:04:48.450 --> 00:04:50.720 Which is our stationery. 00:04:51.090 --> 00:04:51.630 OK. 00:04:51.630 --> 00:04:53.240 You can use that function as well. 00:04:53.400 --> 00:04:55.360 OK. 00:04:55.740 --> 00:05:00.170 Now we're also checking that the Remember Me cookie exists. 00:05:00.210 --> 00:05:00.720 OK. 00:05:00.810 --> 00:05:03.560 So you going to check that the cookie is not empty. 00:05:03.870 --> 00:05:04.500 OK. 00:05:04.500 --> 00:05:13.110 So we're going to use the opposites of the empty function like box and the promise of the function is 00:05:13.110 --> 00:05:13.680 going to be 00:05:16.710 --> 00:05:23.820 the elements in the cookie array. 00:05:26.810 --> 00:05:30.400 Pay corresponding to the key. 00:05:31.410 --> 00:05:33.770 Remember me. 00:05:35.570 --> 00:05:36.350 OK. 00:05:36.770 --> 00:05:42.560 Now if these conditions are fulfilled then we know that the user is remembered and we know that there 00:05:42.560 --> 00:05:43.700 is a cookie. 00:05:43.830 --> 00:05:44.150 OK. 00:05:44.150 --> 00:05:49.620 And also we know that we stored variables in the Remember table. 00:05:49.620 --> 00:05:58.980 So if we go back to our logging file and look at the functions we use for the cookie and for storing 00:05:58.980 --> 00:06:00.640 the variables in the table. 00:06:01.000 --> 00:06:01.780 OK so here goes. 00:06:01.800 --> 00:06:03.000 Function F 1. 00:06:03.310 --> 00:06:04.570 OK. 00:06:05.370 --> 00:06:12.090 Which is the concatenation of the first variable. 00:06:12.440 --> 00:06:19.130 The second variable while we're reversing the second variable from binary to decimal. 00:06:19.300 --> 00:06:19.720 OK. 00:06:20.000 --> 00:06:27.140 So let's just copy that and keep his other comments to make something easier. 00:06:28.070 --> 00:06:33.640 OK so that's the cookie. 00:06:33.770 --> 00:06:37.940 And when we saw the variables in the table we used the function f 2 00:06:43.350 --> 00:06:43.860 which 00:06:46.880 --> 00:06:53.230 is the second variable using S.A.G. to 5:6. 00:06:55.120 --> 00:06:56.420 OK. 00:06:56.670 --> 00:07:07.890 So as if one has to know the first thing we're going to do is to extract the variables one and two from 00:07:07.880 --> 00:07:08.700 the cookie. 00:07:08.940 --> 00:07:10.620 OK. 00:07:11.750 --> 00:07:12.770 So that's the first step 00:07:12.770 --> 00:07:26.170 . 00:07:28.380 --> 00:07:34.110 Then later on we're going to compare the values we get from the cookie with the ones that we've got 00:07:34.130 --> 00:07:36.790 in our memory table. 00:07:37.190 --> 00:07:43.730 OK so now it's extracts the to all sorts cases from the cookie. 00:07:43.910 --> 00:07:50.490 The first thing we're going to do is divide the cookie to two bits the bits that is on the left hand 00:07:50.490 --> 00:07:55.720 side of the comma and the other bits which is on the right hand side of the column. 00:07:56.030 --> 00:07:57.070 OK. 00:07:57.140 --> 00:08:03.660 And then this will give us all all we cater to all the defecates of one but is going to give us all 00:08:03.650 --> 00:08:06.610 that's be to in Exodus. 00:08:06.960 --> 00:08:12.060 And then we're going to convert that to binary. 00:08:12.060 --> 00:08:12.500 OK. 00:08:12.620 --> 00:08:15.480 So that we can guess the original variable. 00:08:15.810 --> 00:08:17.790 Ok so let's go ahead and do this so 00:08:21.600 --> 00:08:26.350 to divide our cookie we are going to use a function called explode. 00:08:26.810 --> 00:08:28.450 OK. 00:08:29.250 --> 00:08:34.260 So this function is going to take a couple of promises. 00:08:34.280 --> 00:08:40.360 So the first promiser is going to be the criteria we're going to use in order to divide the cooking 00:08:40.370 --> 00:08:40.460 . 00:08:40.470 --> 00:08:40.910 OK. 00:08:40.930 --> 00:08:43.510 We're going to use the comma criteria. 00:08:43.620 --> 00:08:45.080 OK. 00:08:46.230 --> 00:08:54.190 And then we're going to give our function the value of the cookie itself. 00:08:54.770 --> 00:08:56.680 OK. 00:08:57.770 --> 00:09:07.120 So this function explode is going to return an array of strings. 00:09:07.230 --> 00:09:09.480 So it took two promises the delimiter. 00:09:09.500 --> 00:09:10.700 What are criteria. 00:09:10.760 --> 00:09:12.650 The comma there and our string. 00:09:12.680 --> 00:09:16.520 And he's going to return an array of strings. 00:09:17.030 --> 00:09:17.850 OK. 00:09:17.850 --> 00:09:26.790 Now we need to store the values inside this array inside our variables. 00:09:26.840 --> 00:09:30.250 All this scientific data one and all vacated too. 00:09:30.380 --> 00:09:33.750 So to do this we're going to use another function called List. 00:09:34.120 --> 00:09:45.530 OK so this function is going to take a couple of times is in our case files as we cater 1 and 2. 00:09:45.570 --> 00:09:47.170 OK. 00:09:47.390 --> 00:09:52.270 And he's going to assign the values returned inside the array. 00:09:52.770 --> 00:09:55.660 OK let's we get. 00:09:55.670 --> 00:10:02.070 Using the function explode is going to assign those values to all advocates of one and or advocate or 00:10:02.080 --> 00:10:02.590 two. 00:10:02.930 --> 00:10:04.260 OK. 00:10:04.430 --> 00:10:11.620 Or it's now the only problem we have is that all these it too. 00:10:11.930 --> 00:10:14.190 We're going to get it and it is simple. 00:10:14.340 --> 00:10:23.360 OK now we're going to need to turn it to binary So just going to use the function ex-head is similar 00:10:23.510 --> 00:10:24.800 to binary. 00:10:25.110 --> 00:10:26.010 OK. 00:10:26.000 --> 00:10:28.150 Of the variable itself. 00:10:28.730 --> 00:10:33.940 And now we've got exactly the original. 00:10:33.940 --> 00:10:38.010 All this because we created in the logging file. 00:10:38.360 --> 00:10:45.990 Ok now we're going to go to the Remember Me table and match these values as we've called for our two 00:10:45.990 --> 00:10:48.750 variables with whatever we stored in there. 00:10:48.760 --> 00:10:49.190 OK. 00:10:49.290 --> 00:10:53.380 So if you remember all this because of what was stored as it is. 00:10:53.610 --> 00:10:58.980 But we thought if to of all this because it two in this column. 00:10:59.210 --> 00:10:59.680 OK. 00:10:59.790 --> 00:11:08.720 So what are we going to do we going to create another variable f to of all this because it to. 00:11:10.640 --> 00:11:22.020 Which is F to of all this Vicary to instead of defining the function again we can just use the formula 00:11:22.200 --> 00:11:23.220 straight away. 00:11:23.640 --> 00:11:25.900 OK. 00:11:27.240 --> 00:11:32.410 Which is just the hash of authors we cater to. 00:11:32.730 --> 00:11:35.100 All right. 00:11:35.880 --> 00:11:39.610 Now the first thing we're going to do is find a record in our table. 00:11:39.710 --> 00:11:40.300 OK. 00:11:40.530 --> 00:11:46.190 Where the author advocates a one column much is our first variable. 00:11:46.200 --> 00:11:48.840 Ok so let's write our query 00:11:48.850 --> 00:11:59.140 . 00:12:08.790 --> 00:12:16.440 So you're going to select the records from our table. 00:12:16.440 --> 00:12:19.630 Remember me. 00:12:22.220 --> 00:12:23.520 OK. 00:12:24.750 --> 00:12:30.880 Where the first column. 00:12:31.820 --> 00:12:33.080 OK. 00:12:33.570 --> 00:12:38.720 Much as the value of our first variable 00:12:41.580 --> 00:12:43.520 was in Decatur 1. 00:12:43.940 --> 00:12:45.240 OK. 00:12:45.330 --> 00:12:52.800 Now we're going to run the query and so the results in the results variable. 00:12:52.880 --> 00:12:59.840 So to run the query using the function my is choli query. 00:12:59.940 --> 00:13:01.510 Gary takes couple of promises. 00:13:01.510 --> 00:13:07.880 I would link variable and query. 00:13:08.040 --> 00:13:15.140 Right now we're going to check if the query has been successful. 00:13:15.140 --> 00:13:16.860 OK has been run successfully. 00:13:16.860 --> 00:13:21.400 So we're going to check the opposites of the results variable. 00:13:21.420 --> 00:13:27.420 So if the query is not successful results is going to be resetting a boolean false and the opposite 00:13:27.480 --> 00:13:29.510 of it is going to be true. 00:13:29.940 --> 00:13:33.230 So if that's the case we're going to echo an error message. 00:13:33.330 --> 00:13:38.760 OK so let's copy the error message from somewhere 00:13:43.270 --> 00:13:47.900 and write some text in there. 00:13:48.030 --> 00:13:56.850 We're going to say something like there was an error in the query. 00:13:58.690 --> 00:13:59.470 OK. 00:13:59.880 --> 00:14:04.680 Now if the query is successful are we going to write some other code. 00:14:05.340 --> 00:14:11.300 So we're expecting one record only in the results objects and we going to need to check that. 00:14:11.370 --> 00:14:12.030 OK. 00:14:12.300 --> 00:14:17.770 So we can use the same code we used in the logging file. 00:14:18.060 --> 00:14:18.390 OK 00:14:18.380 --> 00:14:25.220 . 00:14:25.230 --> 00:14:30.800 And instead of using the L statements you can use the exits 00:14:33.480 --> 00:14:40.190 keyword OK or function and then write some code after the if statements. 00:14:40.320 --> 00:14:48.060 OK so we're defining a variable count where we are storing the number of records in the result object 00:14:48.070 --> 00:14:48.210 . 00:14:48.330 --> 00:14:49.240 OK. 00:14:49.440 --> 00:14:53.850 If count is different than 1 then we're going to echo an error. 00:14:54.240 --> 00:14:55.150 OK. 00:14:55.980 --> 00:14:57.240 So let's say something like 00:15:00.140 --> 00:15:01.760 Remember Me process 00:15:07.340 --> 00:15:10.340 failed something like this. 00:15:10.810 --> 00:15:11.930 OK. 00:15:12.160 --> 00:15:22.350 And then we go in to fetch the record inside the results object. 00:15:22.460 --> 00:15:25.730 OK so we're going to find a variable row. 00:15:26.500 --> 00:15:27.300 OK. 00:15:27.820 --> 00:15:32.650 And before that let's just exit here as well. 00:15:34.590 --> 00:15:35.120 OK. 00:15:35.380 --> 00:15:38.050 So we're going to check that if there is an error. 00:15:38.050 --> 00:15:39.630 We're going to exit the whole code here. 00:15:39.750 --> 00:15:40.040 OK. 00:15:40.060 --> 00:15:41.620 We're going to continue. 00:15:41.840 --> 00:15:43.460 We're going to check that as well. 00:15:43.520 --> 00:15:47.190 We're going to exit if the count is different than one. 00:15:47.290 --> 00:15:48.650 And then if everything is fine. 00:15:48.750 --> 00:15:50.930 We're going to define these variable. 00:15:50.920 --> 00:15:55.220 Row where are we going to store the record. 00:15:55.220 --> 00:15:55.700 OK. 00:15:55.750 --> 00:16:03.010 So you go inside the results object so we're going to use the function my Eskil I fetch every OK we 00:16:03.010 --> 00:16:05.160 used before. 00:16:06.010 --> 00:16:09.850 So this function again takes a couple of promises. 00:16:09.860 --> 00:16:12.260 The first one is going to be our result objects. 00:16:12.250 --> 00:16:21.960 The second one is optional and we are going to use it to have a positive array. 00:16:22.020 --> 00:16:22.910 OK. 00:16:23.450 --> 00:16:28.780 It can either go for numeric or associative So we're going to go for a stative you can go for both as 00:16:28.780 --> 00:16:29.740 well if you want. 00:16:30.100 --> 00:16:41.360 OK so now we are going to compare the value we find in the F to all those vacated to column with the 00:16:41.440 --> 00:16:42.130 value 00:16:45.590 --> 00:16:50.880 of the variable f to all those vacated to that we created earlier. 00:16:51.190 --> 00:16:52.360 OK. 00:16:52.900 --> 00:16:58.700 So if those two values much OK then we're going to allow the user to log in. 00:16:58.750 --> 00:16:59.300 OK. 00:16:59.290 --> 00:17:02.640 We're going to look them in. 00:17:04.930 --> 00:17:13.100 So so far we have covered this Ted what is looking for the first variable k and that's one. 00:17:13.120 --> 00:17:18.520 Now we're going to do this one. 00:17:18.530 --> 00:17:22.830 OK. 00:17:25.120 --> 00:17:33.610 So we're going to have an if statement so when comparing to hushes there is a function you can use it's 00:17:33.620 --> 00:17:36.570 called harsh equals like this. 00:17:39.260 --> 00:17:41.100 So it's going to take a couple of promises. 00:17:41.170 --> 00:17:42.590 OK. 00:17:42.590 --> 00:17:54.260 So the first one is going to be the elements of key to all things vacated to in our record. 00:17:54.350 --> 00:18:03.260 OK say one record there and we're going to look at that element of key to all those vacated. 00:18:03.590 --> 00:18:12.270 OK so it's going to be a row then the index we're looking at is where the key is F to us and see if 00:18:12.280 --> 00:18:15.570 we cater to. 00:18:15.830 --> 00:18:24.920 OK then the second value or promiser is going to be our variable. 00:18:24.920 --> 00:18:31.280 So we created earlier if two of them became too. 00:18:32.120 --> 00:18:34.330 OK. 00:18:34.380 --> 00:18:40.860 So if these two values are equal the function equals is going to return true. 00:18:41.070 --> 00:18:49.710 OK so if that's the case we're going to lock the user in by setting their session variables. 00:18:49.790 --> 00:18:50.280 OK. 00:18:50.390 --> 00:18:56.110 They're going to set the elements of key user ID. 00:18:56.950 --> 00:19:01.070 OK the user ID can be found 00:19:04.580 --> 00:19:06.020 in the record. 00:19:06.160 --> 00:19:06.550 OK. 00:19:06.570 --> 00:19:09.550 That's how you got there by using the ID column. 00:19:09.560 --> 00:19:16.850 So that's going to be the elements in our row array will pay off the 00:19:21.350 --> 00:19:22.950 ID of the user. 00:19:23.350 --> 00:19:28.850 And actually that's the column user ID we there that's the ID of our user. 00:19:28.950 --> 00:19:30.920 OK in the Remember Me table. 00:19:31.280 --> 00:19:32.020 That's right. 00:19:32.190 --> 00:19:33.310 OK. 00:19:33.350 --> 00:19:35.590 So here we go. 00:19:35.680 --> 00:19:39.280 So user right. 00:19:39.780 --> 00:19:40.300 All right. 00:19:40.310 --> 00:19:46.810 Now we at our user in but before we redirect them to the Notes page we're going to regenerate new authors 00:19:46.830 --> 00:19:51.210 of cases and store them in a cookie and they remember the table which will do the next video