PHP-and-MySQL/C4/Cookies-Part-2/English-timed

From Script | Spoken-Tutorial
Revision as of 17:22, 24 March 2017 by PoojaMoolya (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
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.

Contributors and Content Editors

Gyan, PoojaMoolya, Pratik kamble, Sandhya.np14