Difference between revisions of "PHP-and-MySQL/C4/Cookies-Part-2/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) |
|||
(One intermediate revision by one other user not shown) | |||
Line 4: | Line 4: | ||
|- | |- | ||
|00:00 | |00:00 | ||
− | |Welcome back. Just to | + | |Welcome back. Just to summarize - 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. |
|- | |- | ||
|00:13 | |00:13 | ||
− | |Using this command here, we also learnt how to print out every cookie that we had stored. | + | |Using this '''command''' here, we also learnt how to print out every '''cookie''' that we had stored. |
|- | |- | ||
|00:18 | |00:18 | ||
− | |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. | + | |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. |
|- | |- | ||
|00:28 | |00:28 | ||
− | |To do so, we will use a function called | + | |To do so, we will use a function called '''isset()'''. |
|- | |- | ||
|00:32 | |00:32 | ||
− | |This basically returns a true or false value depending on whether something is set or not. | + | |This basically returns a '''true''' or '''false''' value depending on whether something is set or not. |
|- | |- | ||
|00:37 | |00:37 | ||
− | |For example | + | |For example, a cookie. I'll put a dollar sign then underscore '''cookie'''. |
|- | |- | ||
|00:42 | |00:42 | ||
Line 25: | Line 25: | ||
|- | |- | ||
|00:46 | |00:46 | ||
− | |So if I read this out in English language then I'll say - | + | |So, if I read this out in English language then I'll say - |
|- | |- | ||
|00:49 | |00:49 | ||
Line 31: | Line 31: | ||
|- | |- | ||
|00:57 | |00:57 | ||
− | |Otherwise we will echo out to the user that "Cookie is not set". | + | |Otherwise we will '''echo''' out to the user that "Cookie is not set". |
|- | |- | ||
|01:01 | |01:01 | ||
− | |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". | + | |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". |
|- | |- | ||
|01:11 | |01:11 | ||
− | |Now I'll teach you how to 'unset' a cookie. | + | |Now I'll teach you how to 'unset' a '''cookie'''. |
|- | |- | ||
|01:14 | |01:14 | ||
− | |So | + | |So, let's say over here - just before our '''if''' statement, I wish to unset my cookie. |
|- | |- | ||
|01:20 | |01:20 | ||
− | |So unset a cookie. | + | |So, unset a cookie. So, just to name one, I'll unset this cookie, |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
|01:25 | |01:25 | ||
− | |presuming that if you learn to unset this one you can unset this one too. | + | |presuming that if you learn to unset this one, you can unset this one too. |
|- | |- | ||
|01:31 | |01:31 | ||
− | |So I'll unset this name cookie. | + | |So, I'll unset this "name" '''cookie'''. |
|- | |- | ||
|01:34 | |01:34 | ||
− | |So to unset we use the same command and that’s 'setcookie'. | + | |So, to unset, we use the same command and that’s 'setcookie()'. |
|- | |- | ||
|01:39 | |01:39 | ||
Line 70: | Line 67: | ||
|- | |- | ||
|01:51 | |01:51 | ||
− | |I'll create a new one with " | + | |I'll create a new one with "$exp_unset" |
|- | |- | ||
|01:55 | |01:55 | ||
− | | | + | |and that is gonna equal to the time minus 86400. |
|- | |- | ||
|02:01 | |02:01 | ||
− | |Here we said plus which meant that the time is in the future. | + | |Here, we said plus which meant that the time is in the future. |
|- | |- | ||
|02:05 | |02:05 | ||
Line 82: | Line 79: | ||
|- | |- | ||
|02:13 | |02:13 | ||
− | |So if I were to say - set a cookie that already exists called name, to 'no value' at all. | + | |So. if I were to say - set a cookie that already exists called name, to 'no value' at all. |
|- | |- | ||
|02:20 | |02:20 | ||
− | |And use | + | |And use “$exp_unset” variable to set it to a time in the future, thereby 'unsetting' our cookie. |
|- | |- | ||
|02:28 | |02:28 | ||
− | |So I'll get rid of this code for now and run this page, okay? | + | |So, I'll get rid of this code for now and run this page, okay? |
|- | |- | ||
|02:34 | |02:34 | ||
Line 94: | Line 91: | ||
|- | |- | ||
|02:40 | |02:40 | ||
− | |Now I want to get rid of this code - so I'll comment this out. | + | |Now I want to get rid of this code - so I'll '''comment''' this out. |
|- | |- | ||
|02:45 | |02:45 | ||
− | |And I'll put my 'if' statement back into | + | |And I'll put my '''if''' statement back into the page. |
|- | |- | ||
|02:48 | |02:48 | ||
Line 103: | Line 100: | ||
|- | |- | ||
|02:56 | |02:56 | ||
− | | | + | |Let's refresh and we got "Cookie is not set". |
|- | |- | ||
|03:02 | |03:02 | ||
Line 109: | Line 106: | ||
|- | |- | ||
|03:08 | |03:08 | ||
− | |To change the value of a cookie, you'll have to use 'setcookie' command again. | + | |To change the value of a cookie, you'll have to use 'setcookie()' command again. |
|- | |- | ||
|03:13 | |03:13 | ||
− | |You’ll say - set cookie name and here just type a new value | + | |You’ll say - '''set cookie''' "name" and here just type a new value. |
|- | |- | ||
|03:17 | |03:17 | ||
− | |So | + | |So, it's not hard to work with '''cookies'''. |
|- | |- | ||
|03:19 | |03:19 | ||
− | | | + | |It's quite an easy process. |
|- | |- | ||
|03:21 | |03:21 | ||
− | |And it’s a very very useful thing in php | + | |And it’s a very very useful thing in '''php'''. |
|- | |- | ||
|03:23 | |03:23 | ||
− | |So use it to your heart’s content. Okay. Thanks for watching. | + | |So, use it to your heart’s content. Okay. Thanks for watching. |
|- | |- | ||
|03:27 | |03:27 | ||
Line 130: | Line 127: | ||
|- | |- | ||
|03:30 | |03:30 | ||
− | |This is Evan Varkey dubbing for the Spoken Tutorial Project. Bye. | + | |This is Evan Varkey, dubbing for the Spoken Tutorial Project. Bye. |
Latest revision as of 17:22, 24 March 2017
Time | Narration |
00:00 | Welcome back. Just to summarize - 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. |
00:13 | Using this command here, we also learnt how to print out every cookie that we had stored. |
00:18 | 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. |
00:28 | To do so, we will use a function called isset(). |
00:32 | This basically returns a true or false value depending on whether something is set or not. |
00:37 | For example, a cookie. I'll put a dollar sign then underscore cookie. |
00:42 | And I'll put 'name' in here. |
00:46 | So, if I read this out in English language then I'll say - |
00:49 | If the cookie name is set then we say echo “Cookie is set”. |
00:57 | Otherwise we will echo out to the user that "Cookie is not set". |
01:01 | 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". |
01:11 | Now I'll teach you how to 'unset' a cookie. |
01:14 | So, let's say over here - just before our if statement, I wish to unset my cookie. |
01:20 | So, unset a cookie. So, just to name one, I'll unset this cookie, |
01:25 | presuming that if you learn to unset this one, you can unset this one too. |
01:31 | So, I'll unset this "name" cookie. |
01:34 | So, to unset, we use the same command and that’s 'setcookie()'. |
01:39 | So we are resetting a cookie. |
01:41 | This doesn’t seem to make any sense but it will soon. |
01:45 | Now we will set the cookie name to nothing. |
01:49 | And our expiry date here... |
01:51 | I'll create a new one with "$exp_unset" |
01:55 | and that is gonna equal to the time minus 86400. |
02:01 | Here, we said plus which meant that the time is in the future. |
02:05 | Now by setting the cookie to this variable which represents a time in the future, we are actually unsetting the cookie. |
02:13 | So. if I were to say - set a cookie that already exists called name, to 'no value' at all. |
02:20 | And use “$exp_unset” variable to set it to a time in the future, thereby 'unsetting' our cookie. |
02:28 | So, I'll get rid of this code for now and run this page, okay? |
02:34 | Nothing has happened presuming my cookie is unset. |
02:40 | Now I want to get rid of this code - so I'll comment this out. |
02:45 | And I'll put my if statement back into the page. |
02:48 | 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". |
02:56 | Let's refresh and we got "Cookie is not set". |
03:02 | And then from here you can set it again if you like and you can change the values of the cookie. |
03:08 | To change the value of a cookie, you'll have to use 'setcookie()' command again. |
03:13 | You’ll say - set cookie "name" and here just type a new value. |
03:17 | So, it's not hard to work with cookies. |
03:19 | It's quite an easy process. |
03:21 | And it’s a very very useful thing in php. |
03:23 | So, use it to your heart’s content. Okay. Thanks for watching. |
03:27 | If you have any questions, please let me know. |
03:30 | This is Evan Varkey, dubbing for the Spoken Tutorial Project. Bye. |