Difference between revisions of "PHP-and-MySQL/C4/Cookies-Part-1/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{|Border=1 !Time !Narration |- |0:00 |Welcome to this tutorial on php cookies. |- |0:04 |Cookies are a very important part when creating special websites where you store inform…')
 
Line 1: Line 1:
 
{|Border=1
 
{|Border=1
!Time
+
|'''Time'''
!Narration
+
|'''Narration'''
 
|-
 
|-
|0:00
+
|00:00
 
|Welcome to this tutorial on php cookies.   
 
|Welcome to this tutorial on php cookies.   
 
|-
 
|-
|0:04
+
|00:04
 
|Cookies are a very important part when creating special websites where you store information about a user.
 
|Cookies are a very important part when creating special websites where you store information about a user.
 
|-
 
|-
|0:11
+
|00:11
 
|The definition of a cookie is a set of data stored on your computer or the user's computer by the web server.
 
|The definition of a cookie is a set of data stored on your computer or the user's computer by the web server.
 
|-
 
|-
|0:18
+
|00:18
 
|This means, that when we go to a website, our details are stored and are used when we visit it again, provided we select an option like 'Remember me'.
 
|This means, that when we go to a website, our details are stored and are used when we visit it again, provided we select an option like 'Remember me'.
 
|-
 
|-
|0:30
+
|00:30
 
|So you don't have to keep logging in.  
 
|So you don't have to keep logging in.  
 
|-
 
|-
|0:32
+
|00:32
 
|But if you didn't check a button like 'remember me', you will probably be dealing with sessions which close as soon as the user closes the browser.
 
|But if you didn't check a button like 'remember me', you will probably be dealing with sessions which close as soon as the user closes the browser.
 
|-
 
|-
|0:42
+
|00:42
 
|So sessions are killed straight away however cookies are stored for later use.   
 
|So sessions are killed straight away however cookies are stored for later use.   
 
|-
 
|-
|0:50
+
|00:50
 
|So lets begin right away and see how to create a cookie.
 
|So lets begin right away and see how to create a cookie.
 
|-
 
|-
|0:53
+
|00:53
 
|You do this by using the setcookie function.
 
|You do this by using the setcookie function.
 
|-
 
|-
|0:55
+
|00:55
 
|The function takes 5 parameters but I will use just 3.
 
|The function takes 5 parameters but I will use just 3.
 
|-
 
|-
|1:00
+
|01:00
 
|The first vital one I will use is the name of the cookie which I will set to 'name'.
 
|The first vital one I will use is the name of the cookie which I will set to 'name'.
 
|-
 
|-
|1:05
+
|01:05
 
|The second one is the data that needs to be stored inside this cookie and I'll type Alex here.
 
|The second one is the data that needs to be stored inside this cookie and I'll type Alex here.
 
|-
 
|-
|1:12
+
|01:12
 
|Now the next one's a bit more tricky.
 
|Now the next one's a bit more tricky.
 
|-
 
|-
|1:15
+
|01:15
 
|Its the time in which it expires.
 
|Its the time in which it expires.
 
|-
 
|-
|1:18
+
|01:18
 
|Now this needs to be set in seconds.
 
|Now this needs to be set in seconds.
 
|-
 
|-
|1:21
+
|01:21
 
|And to represent this I am going to create a variable called 'exp' for expire and this will be equal to the time.
 
|And to represent this I am going to create a variable called 'exp' for expire and this will be equal to the time.
 
|-
 
|-
|1:28
+
|01:28
 
|Let me add some value here.
 
|Let me add some value here.
 
|-
 
|-
|1:31
+
|01:31
 
|At the moment I am adding zero.
 
|At the moment I am adding zero.
 
|-
 
|-
|1:33
+
|01:33
 
|So if I echo this out and get rid of this cookie function for now.
 
|So if I echo this out and get rid of this cookie function for now.
 
|-
 
|-
|1:39
+
|01:39
 
|I'm just echoing out the time here just to show you what it does.
 
|I'm just echoing out the time here just to show you what it does.
 
|-
 
|-
|1:43
+
|01:43
 
|So lets refresh.  So you can see quite a lot of digits here.
 
|So lets refresh.  So you can see quite a lot of digits here.
 
|-
 
|-
|1:47
+
|01:47
 
|Now this is the unique time-stamp.  
 
|Now this is the unique time-stamp.  
 
|-
 
|-
|1:50
+
|01:50
 
|And the unique time-stamp is the number of seconds before January the 1st 1970.
 
|And the unique time-stamp is the number of seconds before January the 1st 1970.
 
|-
 
|-
|1:56
+
|01:56
 
|So January the 1st at 12 am ummmm...... in the year 1970.
 
|So January the 1st at 12 am ummmm...... in the year 1970.
 
|-
 
|-
|2:02
+
|02:02
 
|So you can see it here - I think the number of seconds in here equates to a date in the future.
 
|So you can see it here - I think the number of seconds in here equates to a date in the future.
 
|-
 
|-
|2:10
+
|02:10
 
|So for example, at this moment you can see this 88, now 89 and as I keep refreshing, by every second this increases.
 
|So for example, at this moment you can see this 88, now 89 and as I keep refreshing, by every second this increases.
 
|-
 
|-
|2:20
+
|02:20
 
|So yes, this is quite useful way of adding a specific value here.
 
|So yes, this is quite useful way of adding a specific value here.
 
|-
 
|-
|2:28
+
|02:28
 
|Now we need to find out the time in seconds of a day because I want this cookie to expire in a day.
 
|Now we need to find out the time in seconds of a day because I want this cookie to expire in a day.
 
|-
 
|-
|2:34
+
|02:34
 
|So I multiply 24 by 60 to get the number of minutes in a day.  
 
|So I multiply 24 by 60 to get the number of minutes in a day.  
 
|-
 
|-
|2:39
+
|02:39
 
|And then multiply the answer by  60 to get the number of seconds in a day which is 86,400.   
 
|And then multiply the answer by  60 to get the number of seconds in a day which is 86,400.   
 
|-
 
|-
|2:47
+
|02:47
 
|So if I replace zero with 86400, we have the variable "expire" that now holds the time in the future by a day.  
 
|So if I replace zero with 86400, we have the variable "expire" that now holds the time in the future by a day.  
 
|-
 
|-
|2:56
+
|02:56
 
|To save time, I am copying this and I will add my expire variable here.
 
|To save time, I am copying this and I will add my expire variable here.
 
|-
 
|-
|3:02
+
|03:02
 
|So this function will set our cookie called 'name' with a value of 'Alex' and it will expire in a day - read in seconds using the time function here.
 
|So this function will set our cookie called 'name' with a value of 'Alex' and it will expire in a day - read in seconds using the time function here.
 
|-
 
|-
|3:13
+
|03:13
 
|So lets refresh this page and hey! we can see we have no errors which means it has worked.  
 
|So lets refresh this page and hey! we can see we have no errors which means it has worked.  
 
|-
 
|-
|3:19
+
|03:19
 
|Now what I'll do is I'll use block commenting to comment out all of these.  
 
|Now what I'll do is I'll use block commenting to comment out all of these.  
 
|-
 
|-
|3:23
+
|03:23
 
|And below this I'll echo out this cookie.
 
|And below this I'll echo out this cookie.
 
|-
 
|-
|3:26
+
|03:26
 
|But the reason I have commented this is because you don't need to set a cookie every time the user comes into the page.  
 
|But the reason I have commented this is because you don't need to set a cookie every time the user comes into the page.  
 
|-
 
|-
|3:33
+
|03:33
 
|If you are using a log in script and you let the user log into your website, you would need to issue this only once and then the cookie will be stored.
 
|If you are using a log in script and you let the user log into your website, you would need to issue this only once and then the cookie will be stored.
 
|-
 
|-
|3:41
+
|03:41
 
|And you could use it within this time that we have set here.
 
|And you could use it within this time that we have set here.
 
|-
 
|-
|3:46
+
|03:46
 
|So what I'll do is I'll set echo and I'll use a dollar sign, sorry, underscore cookie.  
 
|So what I'll do is I'll set echo and I'll use a dollar sign, sorry, underscore cookie.  
 
|-
 
|-
|3:52
+
|03:52
 
|Inside here is the name of the cookie so I'll type 'name'. Refresh and you can see 'Alex'.
 
|Inside here is the name of the cookie so I'll type 'name'. Refresh and you can see 'Alex'.
 
|-
 
|-
|3:59
+
|03:59
 
|You can check it out.  Even if I close my browser, restart my computer and came back into this page, it will still read Alex because its been stored into the computer.
 
|You can check it out.  Even if I close my browser, restart my computer and came back into this page, it will still read Alex because its been stored into the computer.
 
|-
 
|-
|4:11
+
|04:11
 
|Okay now if had to set another cookie, let's say, I set another cookie here and this will be 'age' and my age is 19.
 
|Okay now if had to set another cookie, let's say, I set another cookie here and this will be 'age' and my age is 19.
 
|-
 
|-
|4:24
+
|04:24
 
|And my expiry time I'll just keep as this.   
 
|And my expiry time I'll just keep as this.   
 
|-
 
|-
|4:29
+
|04:29
 
|So lets just put this up here.  
 
|So lets just put this up here.  
 
|-
 
|-
|4:31
+
|04:31
 
|We can replace the block commenting with line-comment to keep it neat.
 
|We can replace the block commenting with line-comment to keep it neat.
 
|-
 
|-
|4:36
+
|04:36
 
|So for our expiry time I'll set another cookie in here.  
 
|So for our expiry time I'll set another cookie in here.  
 
|-
 
|-
|4:41
+
|04:41
 
|And that’ll have the same expiry time.  Lets see if I can get it right.  
 
|And that’ll have the same expiry time.  Lets see if I can get it right.  
 
|-
 
|-
|4:46
+
|04:46
 
|Okay so we'll get rid of this.
 
|Okay so we'll get rid of this.
 
|-
 
|-
|4:48
+
|04:48
 
|We’ve set another cookie with the same expiry time.
 
|We’ve set another cookie with the same expiry time.
 
|-
 
|-
|4:51
+
|04:51
 
|Lets refresh. Okay that has been set.
 
|Lets refresh. Okay that has been set.
 
|-
 
|-
|4:55
+
|04:55
 
|So what I'll do is comment this out and here I will echo it out.
 
|So what I'll do is comment this out and here I will echo it out.
 
|-
 
|-
|5:01
+
|05:01
 
|So you see we can set more than one cookie in a page. Lets refresh that and we can get 19.
 
|So you see we can set more than one cookie in a page. Lets refresh that and we can get 19.
 
|-
 
|-
|5:07
+
|05:07
 
|Now we can also set a cookie in a single sentence.  
 
|Now we can also set a cookie in a single sentence.  
 
|-
 
|-
|5:11
+
|05:11
 
|For that I'll type echo underscore cookie, name and the concatenate "is" and then concatenate my age.
 
|For that I'll type echo underscore cookie, name and the concatenate "is" and then concatenate my age.
 
|-
 
|-
|5:27
+
|05:27
 
|Therefore we will have a sentence saying Alex is 19 just from the cookies that we've stored.  
 
|Therefore we will have a sentence saying Alex is 19 just from the cookies that we've stored.  
 
|-
 
|-
|5:34
+
|05:34
 
|And again if I close my browser or restart my computer or come back two hours later, this information will still be there stored on this computer ready to be used by this page.
 
|And again if I close my browser or restart my computer or come back two hours later, this information will still be there stored on this computer ready to be used by this page.
 
|-
 
|-
|5:44
+
|05:44
 
|So you can see that they are really very useful to use and really easy to create as well and easy to echo out the user.  
 
|So you can see that they are really very useful to use and really easy to create as well and easy to echo out the user.  
 
|-
 
|-
|5:53
+
|05:53
 
|Now there's a function we can use called 'print r' or 'print underscore r'.  
 
|Now there's a function we can use called 'print r' or 'print underscore r'.  
 
|-
 
|-
|5:58
+
|05:58
 
|And we can echo out 'dollar underscore cookie' here. We can align it a bit later...
 
|And we can echo out 'dollar underscore cookie' here. We can align it a bit later...
 
|-
 
|-
|6:05
+
|06:05
 
|Refresh this and you can see we've got an array here and we have a different value.  
 
|Refresh this and you can see we've got an array here and we have a different value.  
 
|-
 
|-
|6:12
+
|06:12
 
|We have got name and that is equal to Alex and we've got an age which is equal to 19.  
 
|We have got name and that is equal to Alex and we've got an age which is equal to 19.  
 
|-
 
|-
|6:22
+
|06:22
 
|So these are cookies and they have been set and these are the values of the cookies.
 
|So these are cookies and they have been set and these are the values of the cookies.
 
|-
 
|-
|6:27
+
|06:27
 
|This can be very useful if you want to echo this out to yourself.  
 
|This can be very useful if you want to echo this out to yourself.  
 
|-
 
|-
|6:31
+
|06:31
 
|Okay now there is another function which I will cover in the second part of this tutorial and I'll use an 'if' statement to find out if a cookie is set or not.  
 
|Okay now there is another function which I will cover in the second part of this tutorial and I'll use an 'if' statement to find out if a cookie is set or not.  
 
|-
 
|-
|6:41
+
|06:41
 
|And I'll also show you how to unset a cookie.
 
|And I'll also show you how to unset a cookie.
 
|-
 
|-
|6:45
+
|06:45
 
|So join me in part 2 and thanks for watching.  This is Evan Varkey dubbing for the Spoken Tutorial Project. Bye.
 
|So join me in part 2 and thanks for watching.  This is Evan Varkey dubbing for the Spoken Tutorial Project. Bye.

Revision as of 12:43, 10 July 2014

Time Narration
00:00 Welcome to this tutorial on php cookies.
00:04 Cookies are a very important part when creating special websites where you store information about a user.
00:11 The definition of a cookie is a set of data stored on your computer or the user's computer by the web server.
00:18 This means, that when we go to a website, our details are stored and are used when we visit it again, provided we select an option like 'Remember me'.
00:30 So you don't have to keep logging in.
00:32 But if you didn't check a button like 'remember me', you will probably be dealing with sessions which close as soon as the user closes the browser.
00:42 So sessions are killed straight away however cookies are stored for later use.
00:50 So lets begin right away and see how to create a cookie.
00:53 You do this by using the setcookie function.
00:55 The function takes 5 parameters but I will use just 3.
01:00 The first vital one I will use is the name of the cookie which I will set to 'name'.
01:05 The second one is the data that needs to be stored inside this cookie and I'll type Alex here.
01:12 Now the next one's a bit more tricky.
01:15 Its the time in which it expires.
01:18 Now this needs to be set in seconds.
01:21 And to represent this I am going to create a variable called 'exp' for expire and this will be equal to the time.
01:28 Let me add some value here.
01:31 At the moment I am adding zero.
01:33 So if I echo this out and get rid of this cookie function for now.
01:39 I'm just echoing out the time here just to show you what it does.
01:43 So lets refresh. So you can see quite a lot of digits here.
01:47 Now this is the unique time-stamp.
01:50 And the unique time-stamp is the number of seconds before January the 1st 1970.
01:56 So January the 1st at 12 am ummmm...... in the year 1970.
02:02 So you can see it here - I think the number of seconds in here equates to a date in the future.
02:10 So for example, at this moment you can see this 88, now 89 and as I keep refreshing, by every second this increases.
02:20 So yes, this is quite useful way of adding a specific value here.
02:28 Now we need to find out the time in seconds of a day because I want this cookie to expire in a day.
02:34 So I multiply 24 by 60 to get the number of minutes in a day.
02:39 And then multiply the answer by 60 to get the number of seconds in a day which is 86,400.
02:47 So if I replace zero with 86400, we have the variable "expire" that now holds the time in the future by a day.
02:56 To save time, I am copying this and I will add my expire variable here.
03:02 So this function will set our cookie called 'name' with a value of 'Alex' and it will expire in a day - read in seconds using the time function here.
03:13 So lets refresh this page and hey! we can see we have no errors which means it has worked.
03:19 Now what I'll do is I'll use block commenting to comment out all of these.
03:23 And below this I'll echo out this cookie.
03:26 But the reason I have commented this is because you don't need to set a cookie every time the user comes into the page.
03:33 If you are using a log in script and you let the user log into your website, you would need to issue this only once and then the cookie will be stored.
03:41 And you could use it within this time that we have set here.
03:46 So what I'll do is I'll set echo and I'll use a dollar sign, sorry, underscore cookie.
03:52 Inside here is the name of the cookie so I'll type 'name'. Refresh and you can see 'Alex'.
03:59 You can check it out. Even if I close my browser, restart my computer and came back into this page, it will still read Alex because its been stored into the computer.
04:11 Okay now if had to set another cookie, let's say, I set another cookie here and this will be 'age' and my age is 19.
04:24 And my expiry time I'll just keep as this.
04:29 So lets just put this up here.
04:31 We can replace the block commenting with line-comment to keep it neat.
04:36 So for our expiry time I'll set another cookie in here.
04:41 And that’ll have the same expiry time. Lets see if I can get it right.
04:46 Okay so we'll get rid of this.
04:48 We’ve set another cookie with the same expiry time.
04:51 Lets refresh. Okay that has been set.
04:55 So what I'll do is comment this out and here I will echo it out.
05:01 So you see we can set more than one cookie in a page. Lets refresh that and we can get 19.
05:07 Now we can also set a cookie in a single sentence.
05:11 For that I'll type echo underscore cookie, name and the concatenate "is" and then concatenate my age.
05:27 Therefore we will have a sentence saying Alex is 19 just from the cookies that we've stored.
05:34 And again if I close my browser or restart my computer or come back two hours later, this information will still be there stored on this computer ready to be used by this page.
05:44 So you can see that they are really very useful to use and really easy to create as well and easy to echo out the user.
05:53 Now there's a function we can use called 'print r' or 'print underscore r'.
05:58 And we can echo out 'dollar underscore cookie' here. We can align it a bit later...
06:05 Refresh this and you can see we've got an array here and we have a different value.
06:12 We have got name and that is equal to Alex and we've got an age which is equal to 19.
06:22 So these are cookies and they have been set and these are the values of the cookies.
06:27 This can be very useful if you want to echo this out to yourself.
06:31 Okay now there is another function which I will cover in the second part of this tutorial and I'll use an 'if' statement to find out if a cookie is set or not.
06:41 And I'll also show you how to unset a cookie.
06:45 So join me in part 2 and thanks for watching. This is Evan Varkey dubbing for the Spoken Tutorial Project. Bye.

Contributors and Content Editors

Gyan, Pratik kamble, Sandhya.np14