Difference between revisions of "PHP-and-MySQL/C4/Sessions/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{|Border=1 !Time !Narration |- |0:00 |Hello and welcome to this tutorial on php sessions. |- |0:05 |Sessions are quiet similar to cookies. |- |0:08 |However sessions only have a …')
 
Line 1: Line 1:
 
{|Border=1
 
{|Border=1
!Time
+
|'''Time'''
!Narration
+
|''Narration'''
 
|-
 
|-
|0:00
+
|00:00
 
|Hello and welcome to this tutorial on php sessions.
 
|Hello and welcome to this tutorial on php sessions.
 
|-
 
|-
|0:05
+
|00:05
 
|Sessions are quiet similar to cookies.
 
|Sessions are quiet similar to cookies.
 
|-
 
|-
|0:08
+
|00:08
 
|However sessions only have a temporary time - expiry time.
 
|However sessions only have a temporary time - expiry time.
 
|-
 
|-
|0:12
+
|00:12
 
|They will be destroyed as soon as the browser is closed - all the connection to the page is lost.
 
|They will be destroyed as soon as the browser is closed - all the connection to the page is lost.
 
|-
 
|-
|0:19
+
|00:19
 
|So sessions are not like cookies because you can't set a particular expiry time.
 
|So sessions are not like cookies because you can't set a particular expiry time.
 
|-
 
|-
|0:24
+
|00:24
 
|And they are not stored in the same way.
 
|And they are not stored in the same way.
 
|-
 
|-
|0:28
+
|00:28
 
|I mean, the "id" of the session can be stored in the cookie.  
 
|I mean, the "id" of the session can be stored in the cookie.  
 
|-
 
|-
|0:34
+
|00:34
 
|Or you might have seen in a browser URL something like this.
 
|Or you might have seen in a browser URL something like this.
 
|-
 
|-
|0:40
+
|00:40
 
|I don't remember the name - something equals and a lot of numbers and alphabets as well.
 
|I don't remember the name - something equals and a lot of numbers and alphabets as well.
 
|-
 
|-
|0:47
+
|00:47
 
|So basically sessions are very similar to cookies.
 
|So basically sessions are very similar to cookies.
 
|-
 
|-
|0:50
+
|00:50
 
|However they are not stored for a long period of time - only until the user closes the browser.
 
|However they are not stored for a long period of time - only until the user closes the browser.
 
|-
 
|-
|0:57
+
|00:57
 
|Okay - So sessions are different.
 
|Okay - So sessions are different.
 
|-
 
|-
|1:00
+
|01:00
 
|First of all, we need to declare or call this function called 'session_start'.
 
|First of all, we need to declare or call this function called 'session_start'.
 
|-
 
|-
|1:09
+
|01:09
 
|Now this needs to be at the top of every page that you use sessions in.
 
|Now this needs to be at the top of every page that you use sessions in.
 
|-
 
|-
|1:14
+
|01:14
 
|So if you don't have this and you are trying to echo out a session value or you're trying to set a session, it won't work.
 
|So if you don't have this and you are trying to echo out a session value or you're trying to set a session, it won't work.
 
|-
 
|-
|1:22
+
|01:22
 
|You need the session start code there.
 
|You need the session start code there.
 
|-
 
|-
|1:24
+
|01:24
 
|Now I'll show you the error that comes up when you don't use this so you'll remember it.  
 
|Now I'll show you the error that comes up when you don't use this so you'll remember it.  
 
|-
 
|-
|1:30
+
|01:30
 
|Creating a session is very easy.
 
|Creating a session is very easy.
 
|-
 
|-
|1:34
+
|01:34
 
|Use 'dollar underscore session' and in square brackets give the name of the session.
 
|Use 'dollar underscore session' and in square brackets give the name of the session.
 
|-  
 
|-  
|1:40
+
|01:40
 
|I will type name and equal this value to something.
 
|I will type name and equal this value to something.
 
|-
 
|-
|1:44
+
|01:44
 
|It could be a string data or the new written data.   
 
|It could be a string data or the new written data.   
 
|-
 
|-
|1:48
+
|01:48
 
|Okay so our session is set here.  
 
|Okay so our session is set here.  
 
|-
 
|-
|1:50
+
|01:50
 
|Lets run this for the first time.
 
|Lets run this for the first time.
 
|-
 
|-
|1:53
+
|01:53
 
|So lets refresh.
 
|So lets refresh.
 
|-
 
|-
|1:56
+
|01:56
 
|Okay nothing has happened.  
 
|Okay nothing has happened.  
 
|-
 
|-
|1:58
+
|01:58
 
|I'll comment out this code like I did in my 'Cookies' tutorial.
 
|I'll comment out this code like I did in my 'Cookies' tutorial.
 
|-
 
|-
|2:01
+
|02:01
 
|If you haven't seen that please do so.
 
|If you haven't seen that please do so.
 
|-
 
|-
|2:04
+
|02:04
 
|Next I'll echo out the value of the session that I have set.
 
|Next I'll echo out the value of the session that I have set.
 
|-
 
|-
|2:08
+
|02:08
 
|So that's 'name'.  
 
|So that's 'name'.  
 
|-
 
|-
|2:11
+
|02:11
 
|Please note that this is not going to be executed.
 
|Please note that this is not going to be executed.
 
|-
 
|-
|2:15
+
|02:15
 
|This will be on a completely new page, for all you know.  
 
|This will be on a completely new page, for all you know.  
 
|-
 
|-
|2:19
+
|02:19
 
|But here I'm just starting my session.  
 
|But here I'm just starting my session.  
 
|-
 
|-
|2:21
+
|02:21
 
|I'm getting a session called 'name' that has already been stored by our server.
 
|I'm getting a session called 'name' that has already been stored by our server.
 
|-
 
|-
|2:26
+
|02:26
 
|So lets refresh we can see that is equal to 'Alex'.   
 
|So lets refresh we can see that is equal to 'Alex'.   
 
|-
 
|-
|2:29
+
|02:29
 
|So you can add this and this code onto any page.
 
|So you can add this and this code onto any page.
 
|-
 
|-
|2:33
+
|02:33
 
|So you can have your session start and echo your session name onto your page as long as this has been started on any page of the current session of the browser.  
 
|So you can have your session start and echo your session name onto your page as long as this has been started on any page of the current session of the browser.  
 
|-
 
|-
|2:44
+
|02:44
 
|So for example if I create a new page, add my php code here and say session start.
 
|So for example if I create a new page, add my php code here and say session start.
 
|-
 
|-
|2:49
+
|02:49
 
|And then echo out the session 'name'.  
 
|And then echo out the session 'name'.  
 
|-   
 
|-   
|2:56
+
|02:56
 
|And I'll save this in my sessions folder as new page or new dot php.  
 
|And I'll save this in my sessions folder as new page or new dot php.  
 
|-
 
|-
|3:03
+
|03:03
 
|So when we come back to our page here and we click here, we type new dot php.  
 
|So when we come back to our page here and we click here, we type new dot php.  
 
|-
 
|-
|3:10
+
|03:10
 
|We get exactly the same value, even though we are not working on the same page that we created our session in, we are still able to access it.
 
|We get exactly the same value, even though we are not working on the same page that we created our session in, we are still able to access it.
 
|-
 
|-
|3:18
+
|03:18
 
|However if I was to close my browser and reopen it, this session probably would not  exist.
 
|However if I was to close my browser and reopen it, this session probably would not  exist.
 
|-
 
|-
|3:25
+
|03:25
 
|Hope that is clear.  Now let me show you what happens if you don't put the session start in.  
 
|Hope that is clear.  Now let me show you what happens if you don't put the session start in.  
 
|-
 
|-
|3:31
+
|03:31
 
|You get something similar to this.  
 
|You get something similar to this.  
 
|-
 
|-
|3:33
+
|03:33
 
|Lets go back and check it.
 
|Lets go back and check it.
 
|-
 
|-
|3:36
+
|03:36
 
|What happened here is that we are not getting any output because we haven't started our session.
 
|What happened here is that we are not getting any output because we haven't started our session.
 
|-
 
|-
|3:44
+
|03:44
 
|When we type 'session_start', you can see we get our value as output.  
 
|When we type 'session_start', you can see we get our value as output.  
 
|-
 
|-
|3:51
+
|03:51
 
|The reason I don't have an output is because I don't have that type of error reporting on.
 
|The reason I don't have an output is because I don't have that type of error reporting on.
 
|-
 
|-
|3:56
+
|03:56
 
|But if you did have a specific type of error reporting on, I have a tutorial on that as well, then you would probably get an error.
 
|But if you did have a specific type of error reporting on, I have a tutorial on that as well, then you would probably get an error.
 
|-
 
|-
|4:06
+
|04:06
 
|So you can close this now and I'll show you how to 'unset' a session.
 
|So you can close this now and I'll show you how to 'unset' a session.
 
|-
 
|-
|4:10
+
|04:10
 
|There area 2 ways to do this is.
 
|There area 2 ways to do this is.
 
|-
 
|-
|4:12
+
|04:12
 
|Either unset and then session in brackets to unset our session.
 
|Either unset and then session in brackets to unset our session.
 
|-  
 
|-  
|4:16
+
|04:16
 
|Or use a completely different command altogether and that is 'session_destroy'.
 
|Or use a completely different command altogether and that is 'session_destroy'.
 
|-
 
|-
|4:27
+
|04:27
 
|And the difference between these two commands is 'sessions_destroy' will completely destroy sessions that you currently hold.
 
|And the difference between these two commands is 'sessions_destroy' will completely destroy sessions that you currently hold.
 
|-
 
|-
|4:35
+
|04:35
 
|And 'unset' will unset a particular session.
 
|And 'unset' will unset a particular session.
 
|-
 
|-
|4:40
+
|04:40
 
|So its your choice - You can log the user out and say 'session_destroy'.
 
|So its your choice - You can log the user out and say 'session_destroy'.
 
|-
 
|-
|4:46
+
|04:46
 
|That would clear all current session variables that you hold at the present time.  
 
|That would clear all current session variables that you hold at the present time.  
 
|-
 
|-
|4:50
+
|04:50
 
|Or otherwise you can just 'unset' a specific one.
 
|Or otherwise you can just 'unset' a specific one.
 
|-
 
|-
|4:53
+
|04:53
 
|So what are sessions useful for?
 
|So what are sessions useful for?
 
|-
 
|-
|4:55
+
|04:55
 
|If you've come into a website and see a box like 'Remember me' and you don't check this box, then you would probably be using sessions.
 
|If you've come into a website and see a box like 'Remember me' and you don't check this box, then you would probably be using sessions.
 
|-
 
|-
|5:03
+
|05:03
 
|Because once the users' browser has been closed, you would be logged out.  
 
|Because once the users' browser has been closed, you would be logged out.  
 
|-
 
|-
|5:09
+
|05:09
 
|And when you come back to the website you'll have to re-type your details like your user name and password to login to the website.  
 
|And when you come back to the website you'll have to re-type your details like your user name and password to login to the website.  
 
|-
 
|-
|5:17
+
|05:17
 
|But its different if you are using cookies because you set an expiry time - which means that your username will be logged in or this cookie will be held until you decide to destroy it.
 
|But its different if you are using cookies because you set an expiry time - which means that your username will be logged in or this cookie will be held until you decide to destroy it.
 
|-
 
|-
|5:30
+
|05:30
 
|And we have to create a code to destroy our cookie, like I showed in my 'Cookies' tutorial.  
 
|And we have to create a code to destroy our cookie, like I showed in my 'Cookies' tutorial.  
 
|-
 
|-
|5:35
+
|05:35
 
|So really its your choice whether you use sessions or cookies.
 
|So really its your choice whether you use sessions or cookies.
 
|-
 
|-
|5:40
+
|05:40
 
|Sessions are good for short term - Cookies are good for long term - specific amount of time that you want a piece of data to be held.
 
|Sessions are good for short term - Cookies are good for long term - specific amount of time that you want a piece of data to be held.
 
|-
 
|-
|5:49
+
|05:49
 
|But if you've gone through my php Project - 'Register and login', you'll see that I use sessions.  
 
|But if you've gone through my php Project - 'Register and login', you'll see that I use sessions.  
 
|-
 
|-
|5:56
+
|05:56
 
|This is because I need to use sessions when I'm creating tutorials.
 
|This is because I need to use sessions when I'm creating tutorials.
 
|-
 
|-
|6:00
+
|06:00
 
|However you can take any form of this.
 
|However you can take any form of this.
 
|-
 
|-
|6:03
+
|06:03
 
|It could be a cookie, it could be a session, it is really your choice whether you want to keep the user logged in for a long period of time or not.  
 
|It could be a cookie, it could be a session, it is really your choice whether you want to keep the user logged in for a long period of time or not.  
 
|-
 
|-
|6:11
+
|06:11
 
|So if you've got any questions on this, feel free to contact me.  
 
|So if you've got any questions on this, feel free to contact me.  
 
|-
 
|-
|6:16
+
|06:16
 
|Make sure you subscribe to phpacademy.   
 
|Make sure you subscribe to phpacademy.   
 
|-
 
|-
|6:20
+
|06:20
 
|Thanks for watching.  This is Evan Varkey dubbing for the Spoken Tutorial Project.
 
|Thanks for watching.  This is Evan Varkey dubbing for the Spoken Tutorial Project.

Revision as of 12:47, 10 July 2014

Time Narration'
00:00 Hello and welcome to this tutorial on php sessions.
00:05 Sessions are quiet similar to cookies.
00:08 However sessions only have a temporary time - expiry time.
00:12 They will be destroyed as soon as the browser is closed - all the connection to the page is lost.
00:19 So sessions are not like cookies because you can't set a particular expiry time.
00:24 And they are not stored in the same way.
00:28 I mean, the "id" of the session can be stored in the cookie.
00:34 Or you might have seen in a browser URL something like this.
00:40 I don't remember the name - something equals and a lot of numbers and alphabets as well.
00:47 So basically sessions are very similar to cookies.
00:50 However they are not stored for a long period of time - only until the user closes the browser.
00:57 Okay - So sessions are different.
01:00 First of all, we need to declare or call this function called 'session_start'.
01:09 Now this needs to be at the top of every page that you use sessions in.
01:14 So if you don't have this and you are trying to echo out a session value or you're trying to set a session, it won't work.
01:22 You need the session start code there.
01:24 Now I'll show you the error that comes up when you don't use this so you'll remember it.
01:30 Creating a session is very easy.
01:34 Use 'dollar underscore session' and in square brackets give the name of the session.
01:40 I will type name and equal this value to something.
01:44 It could be a string data or the new written data.
01:48 Okay so our session is set here.
01:50 Lets run this for the first time.
01:53 So lets refresh.
01:56 Okay nothing has happened.
01:58 I'll comment out this code like I did in my 'Cookies' tutorial.
02:01 If you haven't seen that please do so.
02:04 Next I'll echo out the value of the session that I have set.
02:08 So that's 'name'.
02:11 Please note that this is not going to be executed.
02:15 This will be on a completely new page, for all you know.
02:19 But here I'm just starting my session.
02:21 I'm getting a session called 'name' that has already been stored by our server.
02:26 So lets refresh we can see that is equal to 'Alex'.
02:29 So you can add this and this code onto any page.
02:33 So you can have your session start and echo your session name onto your page as long as this has been started on any page of the current session of the browser.
02:44 So for example if I create a new page, add my php code here and say session start.
02:49 And then echo out the session 'name'.
02:56 And I'll save this in my sessions folder as new page or new dot php.
03:03 So when we come back to our page here and we click here, we type new dot php.
03:10 We get exactly the same value, even though we are not working on the same page that we created our session in, we are still able to access it.
03:18 However if I was to close my browser and reopen it, this session probably would not exist.
03:25 Hope that is clear. Now let me show you what happens if you don't put the session start in.
03:31 You get something similar to this.
03:33 Lets go back and check it.
03:36 What happened here is that we are not getting any output because we haven't started our session.
03:44 When we type 'session_start', you can see we get our value as output.
03:51 The reason I don't have an output is because I don't have that type of error reporting on.
03:56 But if you did have a specific type of error reporting on, I have a tutorial on that as well, then you would probably get an error.
04:06 So you can close this now and I'll show you how to 'unset' a session.
04:10 There area 2 ways to do this is.
04:12 Either unset and then session in brackets to unset our session.
04:16 Or use a completely different command altogether and that is 'session_destroy'.
04:27 And the difference between these two commands is 'sessions_destroy' will completely destroy sessions that you currently hold.
04:35 And 'unset' will unset a particular session.
04:40 So its your choice - You can log the user out and say 'session_destroy'.
04:46 That would clear all current session variables that you hold at the present time.
04:50 Or otherwise you can just 'unset' a specific one.
04:53 So what are sessions useful for?
04:55 If you've come into a website and see a box like 'Remember me' and you don't check this box, then you would probably be using sessions.
05:03 Because once the users' browser has been closed, you would be logged out.
05:09 And when you come back to the website you'll have to re-type your details like your user name and password to login to the website.
05:17 But its different if you are using cookies because you set an expiry time - which means that your username will be logged in or this cookie will be held until you decide to destroy it.
05:30 And we have to create a code to destroy our cookie, like I showed in my 'Cookies' tutorial.
05:35 So really its your choice whether you use sessions or cookies.
05:40 Sessions are good for short term - Cookies are good for long term - specific amount of time that you want a piece of data to be held.
05:49 But if you've gone through my php Project - 'Register and login', you'll see that I use sessions.
05:56 This is because I need to use sessions when I'm creating tutorials.
06:00 However you can take any form of this.
06:03 It could be a cookie, it could be a session, it is really your choice whether you want to keep the user logged in for a long period of time or not.
06:11 So if you've got any questions on this, feel free to contact me.
06:16 Make sure you subscribe to phpacademy.
06:20 Thanks for watching. This is Evan Varkey dubbing for the Spoken Tutorial Project.

Contributors and Content Editors

Gyan, Pratik kamble, Sandhya.np14