1 00:00:00 --> 00:00:12 Welcome back. Just to summarise - in the first part of the cookie tutorial, we learnt how to create cookies, how to give an expiry date to the cookie and how to print out specific cookies. 2 00:00:13 --> 00:00:17 Using this command here, we also learnt how to print out every cookie that we had stored. 3 00:00:18 --> 00:00:27 So assuming that we have created these cookies, the next thing I'll do is use this specific cookie here that I have created, to check whether it does exist or not. 4 00:00:28 --> 00:00:31 To do so, we will use a function called “isset”. 5 00:00:32 --> 00:00:36 This basically returns a true or false value depending on whether something is set or not. 6 00:00:37 --> 00:00:41 For example- a cookie ,I'll put a dollar sign then underscore cookie. 7 00:00:42 --> 00:00:45 And I'll put 'name' in here. 8 00:00:46 --> 00:00:48 So if I read this out in English language then I'll say - 9 00:00:49 --> 00:00:56 If the cookie name is set then we say echo “Cookie is set”. 10 00:00:57 --> 00:01:00 Otherwise we will echo out to the user that "Cookie is not set". 11 00:01:01 --> 00:01:10 Assuming that I have set my cookie and everything is working, when I refresh this I'll get the message that the "Cookie is set". 12 00:01:11 --> 00:01:13 Now I'll teach you how to 'unset' a cookie. 13 00:01:14 --> 00:01:19 So lets say over here - just before our 'if' statement, I wish to unset my cookie. 14 00:01:20 --> 00:01:20 So unset a cookie. 15 00:01:21 --> 00:01:24 So just to name one, I'll unset this cookie, 16 00:01:25 --> 00:01:30 presuming that if you learn to unset this one you can unset this one too. 17 00:01:31 --> 00:01:33 So I'll unset this name cookie. 18 00:01:34 --> 00:01:38 So to unset we use the same command and that’s 'setcookie'. 19 00:01:39 --> 00:01:40 So we are resetting a cookie. 20 00:01:41 --> 00:01:44 This doesn’t seem to make any sense but it will soon. 21 00:01:45 --> 00:01:48 Now we will set the cookie name to nothing. 22 00:01:49 --> 00:01:50 And our expiry date here... 23 00:01:51 --> 00:01:54 I'll create a new one with "exp unset" 24 00:01:55 --> 00:02:00 And that is gonna equal to the time minus 86400. 25 00:02:01 --> 00:02:04 Here we said plus which meant that the time is in the future. 26 00:02:05 --> 00:02:12 Now by setting the cookie to this variable which represents a time in the future, we are actually unsetting the cookie. 27 00:02:13 --> 00:02:19 So if I were to say - set a cookie that already exists called name, to 'no value' at all. 28 00:02:20 --> 00:02:27 And use “exp unset” variable to set it to a time in the future, thereby 'unsetting' our cookie. 29 00:02:28 --> 00:02:33 So I'll get rid of this code for now and run this page, okay? 30 00:02:34 --> 00:02:39 Nothing has happened presuming my cookie is unset. 31 00:02:40 --> 00:02:44 Now I want to get rid of this code - so I'll comment this out. 32 00:02:45 --> 00:02:47 And I'll put my 'if' statement back into my page. 33 00:02:48 --> 00:02:55 Now presuming this says - is the cookie set name? I'm going to unset the cookie which should get the result "Cookie is not set". 34 00:02:56 --> 00:03:01 Lets refresh and we got "Cookie is not set". 35 00:03:02 --> 00:03:07 And then from here you can set it again if you like and you can change the values of the cookie. 36 00:03:08 --> 00:03:12 To change the value of a cookie, you'll have to use 'setcookie' command again. 37 00:03:13 --> 00:03:16 You’ll say - set cookie name and here just type a new value 38 00:03:17 --> 00:03:18 So its not hard to work with cookies. 39 00:03:19 --> 00:03:20 Its quiet an easy process. 40 00:03:21 --> 00:03:22 And it’s a very very useful thing in php 41 00:03:23 --> 00:03:26 So use it to your heart’s content. Okay. Thanks for watching. 42 00:03:27 --> 00:03:29 If you have any questions, please let me know. 43 00:03:30 --> 00:03:35 This is Evan Varkey dubbing for the Spoken Tutorial Project. Bye.