WEBVTT 00:00:07.080 --> 00:00:09.620 In this video you get to learn BHB sessions. 00:00:09.690 --> 00:00:11.740 So what's a session. 00:00:12.450 --> 00:00:18.720 A session is just another super global variable like the POST variable or the guess variable where we 00:00:18.930 --> 00:00:20.920 can store some data. 00:00:21.020 --> 00:00:21.710 OK. 00:00:21.930 --> 00:00:27.630 For example when a user looks into a web page would like to store some data like their username for 00:00:27.630 --> 00:00:28.460 example. 00:00:28.850 --> 00:00:29.370 OK. 00:00:29.640 --> 00:00:37.610 So to start a session we're going to use a BHP function. 00:00:38.490 --> 00:00:42.210 It's called session starts. 00:00:42.840 --> 00:00:50.800 So if you explore details about this function you can see that it starts a new session. 00:00:50.810 --> 00:00:52.530 Always use an existing session. 00:00:52.650 --> 00:00:56.110 So he's going to do is going to check if there is already a session. 00:00:56.160 --> 00:01:00.190 If yes then it's just going to set the the variables. 00:01:00.300 --> 00:01:11.340 Otherwise it's just going to create a new session and create a new session id for its OK. 00:01:11.400 --> 00:01:15.130 So slowly I think any promises. 00:01:15.150 --> 00:01:17.010 Ok so now we've got our session started. 00:01:17.010 --> 00:01:22.810 So now we are ready to store any data inside the session to store data. 00:01:23.550 --> 00:01:24.180 OK. 00:01:24.270 --> 00:01:32.140 We are just going to access the array session but we're going to choose a key and value. 00:01:32.310 --> 00:01:34.970 OK. 00:01:34.980 --> 00:01:43.610 So let's say we want to store the user's first name. 00:01:45.300 --> 00:01:47.730 OK. 00:01:49.780 --> 00:01:53.790 And we want to store the user's last name for example 00:01:53.790 --> 00:02:00.250 . 00:02:00.310 --> 00:02:00.920 All right. 00:02:00.930 --> 00:02:08.460 So now if you want to use session data OK we just access the data using the array using the syntax of 00:02:08.460 --> 00:02:09.050 the array. 00:02:09.270 --> 00:02:13.200 So for example if you want to echo a paragraph 00:02:16.830 --> 00:02:30.120 K using these couple of variables it just creates a variable first name then we set it to the elements 00:02:30.390 --> 00:02:38.800 first name and then another variable last name and I reset it to the elements last. 00:02:40.470 --> 00:02:41.070 OK. 00:02:41.250 --> 00:02:48.590 So it's either paragraph let's just say hi followed by the first name space last name. 00:02:48.870 --> 00:02:49.710 OK. 00:02:50.160 --> 00:02:53.810 So if we save a refresh we can see our paragraph there. 00:02:53.980 --> 00:02:58.760 OK so we have used the data stored in inside the session. 00:02:59.070 --> 00:03:05.790 OK so now if you want to remove data from the session OK we're just going to 00:03:08.880 --> 00:03:09.840 move data from 00:03:12.510 --> 00:03:13.450 session. 00:03:13.880 --> 00:03:22.550 OK so first before removing the data if you want to check if that's a variable set. 00:03:22.770 --> 00:03:29.270 We are going to check that's using a function called is set. 00:03:29.530 --> 00:03:33.080 OK so this function. 00:03:33.910 --> 00:03:35.270 Control k 00:03:38.650 --> 00:03:41.520 it will it will just determine if a variable A sets. 00:03:41.740 --> 00:03:42.100 OK. 00:03:42.120 --> 00:03:43.840 And he's not gay. 00:03:44.580 --> 00:03:45.540 So if 00:03:49.200 --> 00:03:51.050 this variable is set 00:03:54.660 --> 00:03:58.400 let's check if we have a first name. 00:04:00.480 --> 00:04:03.170 If yes then why are we going to do. 00:04:03.180 --> 00:04:08.690 We are going to remove it by using the function set. 00:04:08.990 --> 00:04:11.050 OK. 00:04:13.740 --> 00:04:16.920 Just like this. 00:04:16.950 --> 00:04:22.530 OK so the function unset takes as an argument the elements that we would like to remove. 00:04:22.730 --> 00:04:23.220 OK. 00:04:23.340 --> 00:04:29.000 So are you just going to remove the value of these elements. 00:04:29.400 --> 00:04:34.880 And finally if we want to. 00:04:38.180 --> 00:04:45.310 OK let's check first as our elements is not there anymore so let's echo session first name. 00:04:45.390 --> 00:04:52.250 So we have says the see what we get. 00:04:53.880 --> 00:05:00.890 OK so he's not doing anything there because the variable is not there anymore. 00:05:01.240 --> 00:05:04.440 OK. 00:05:07.170 --> 00:05:10.070 You can also try. 00:05:10.080 --> 00:05:10.730 Question mark. 00:05:10.740 --> 00:05:17.550 OK so if you have if that's true then show echo 1 00:05:24.390 --> 00:05:32.580 otherwise 0 they say in French we go. 00:05:32.580 --> 00:05:35.820 So we go 0 because the Bible is not there anymore. 00:05:36.230 --> 00:05:37.970 OK. 00:05:38.010 --> 00:05:42.580 So now to destroy a session. 00:05:42.710 --> 00:05:46.590 OK we can use the 00:05:49.600 --> 00:05:55.920 the PSB function session destroy. 00:05:56.180 --> 00:06:02.970 OK so session destroy is just going to destroy the whole session 00:06:04.240 --> 00:06:07.910 . 00:06:09.150 --> 00:06:16.140 Basically if you want to destroy a session we would need to have the session already there. 00:06:16.200 --> 00:06:21.400 After creating a session we can do everything we want with it's storing data accessing data. 00:06:21.600 --> 00:06:21.930 OK. 00:06:21.930 --> 00:06:26.450 And then at the end we destroy the session using this function. 00:06:27.550 --> 00:06:27.780 OK 00:06:27.820 --> 00:06:33.910 .