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

From Script | Spoken-Tutorial
Revision as of 20:39, 1 December 2012 by Pravin1389 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Time Narration
0:00 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.
0:13 Using this command here, we also learnt how to print out every cookie that we had stored.
0: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.
0:28 To do so, we will use a function called “isset”.
0:32 This basically returns a true or false value depending on whether something is set or not.
0:37 For example- a cookie ,I'll put a dollar sign then underscore cookie.
0:42 And I'll put 'name' in here.
0:46 So if I read this out in English language then I'll say -
0:49 If the cookie name is set then we say echo “Cookie is set”.
0:57 Otherwise we will echo out to the user that "Cookie is not set".
1: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".
1:11 Now I'll teach you how to 'unset' a cookie.
1:14 So lets say over here - just before our 'if' statement, I wish to unset my cookie.
1:20 So unset a cookie.
1:21 So just to name one, I'll unset this cookie,
1:25 presuming that if you learn to unset this one you can unset this one too.
1:31 So I'll unset this name cookie.
1:34 So to unset we use the same command and that’s 'setcookie'.
1:39 So we are resetting a cookie.
1:41 This doesn’t seem to make any sense but it will soon.
1:45 Now we will set the cookie name to nothing.
1:49 And our expiry date here...
1:51 I'll create a new one with "exp unset"
1:55 And that is gonna equal to the time minus 86400.
2:01 Here we said plus which meant that the time is in the future.
2:05 Now by setting the cookie to this variable which represents a time in the future, we are actually unsetting the cookie.
2:13 So if I were to say - set a cookie that already exists called name, to 'no value' at all.
2:20 And use “exp unset” variable to set it to a time in the future, thereby 'unsetting' our cookie.
2:28 So I'll get rid of this code for now and run this page, okay?
2:34 Nothing has happened presuming my cookie is unset.
2:40 Now I want to get rid of this code - so I'll comment this out.
2:45 And I'll put my 'if' statement back into my page.
2: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".
2:56 Lets refresh and we got "Cookie is not set".
3:02 And then from here you can set it again if you like and you can change the values of the cookie.
3:08 To change the value of a cookie, you'll have to use 'setcookie' command again.
3:13 You’ll say - set cookie name and here just type a new value
3:17 So its not hard to work with cookies.
3:19 Its quiet an easy process.
3:21 And it’s a very very useful thing in php
3:23 So use it to your heart’s content. Okay. Thanks for watching.
3:27 If you have any questions, please let me know.
3:30 This is Evan Varkey dubbing for the Spoken Tutorial Project. Bye.

Contributors and Content Editors

Chandrika, Pravin1389