Difference between revisions of "PHP-and-MySQL/C4/User-Login-Part-3/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 7: Line 7:
 
|-
 
|-
 
|00:07
 
|00:07
|Here, we'll create a session in which the user can enter a page and they're allowed to be inside the page as long as they have successfully logged in.  
+
|Here, we'll create a '''session''' in which the user can enter a '''page''' and they're allowed to be inside the page as long as they have successfully logged in.  
 
|-
 
|-
 
|00:16
 
|00:16
|To start any session, we will need a function which is "start session".
+
|To start any '''session''', we will need a function which is '''start session'''.
 
|-
 
|-
 
|00:25
 
|00:25
Line 16: Line 16:
 
|-
 
|-
 
|00:34
 
|00:34
|Right, an error!  So, it must be "session start".  Sorry I was a bit confused there.
+
|Right, an error!  So, it must be '''session_start()'''.  Sorry, I was a bit confused there.
 
|-
 
|-
 
|00:40
 
|00:40
|"Session start", okay? So refresh, resend and "You're in!"
+
|"Session start", okay? So refresh, '''resend''' and "You're in!"
 
|-
 
|-
 
|00:42
 
|00:42
|We've started the session and this lets us add a session variable.  
+
|We've started the '''session''' and this let's us add a session variable.  
 
|-
 
|-
 
|00:51
 
|00:51
|So, "You're in!".  After this I'll say "Click here to enter the secret... no, the member page." okay?  
+
|So, "You're in!".  After this, I'll say "Click here to enter the secret... no, the member page." okay?  
 
|-
 
|-
 
|01:12
 
|01:12
|And this is going to be a link to a page called "member dot php".  
+
|And this is going to be a '''link''' to a '''page''' called "member dot php".  
 
|-
 
|-
 
|01:19  
 
|01:19  
|Let's just recap. As long as we send the right data we're going to say "Click here to enter the member page" which we haven't created yet.  
+
|Let's just recap. As long as we send the right data, we're going to say "Click here to enter the member page" which we haven't created yet.  
 
|-
 
|-
 
|01:30
 
|01:30
|Let me remind you here that we just created our "session start" here, which is very important.  
+
|Let me remind you here that we just created our "session_start()" here which is very important.  
 
|-
 
|-
 
|01:36
 
|01:36
|We're going to create a session and to do this let me start and type here the dollar sign underscore session and then in brackets, in square brackets, we will give it a session name.  
+
|We're going to create a session and to do this, let me start and type here the dollar sign underscore SESSION and then in brackets, in square brackets, we will give it a session name.  
 
|-
 
|-
 
|01:53
 
|01:53
|I'll call it "username" and that will be equal to our "username".  I think I will say "dbusername" because that's a more direct value from the database.
+
|I'll call it "username" and that will be equal to our '''username'''.  I think I will say '$dbusername' because that's a more direct value from the database.
 
|-
 
|-
 
|02:08
 
|02:08
Line 46: Line 46:
 
|-
 
|-
 
|02:10
 
|02:10
|As long as the user is in their browser not the browser you evoked them with, then when we echo out our session in any page now, this will be set as a session.  
+
|As long as the user is in their browser, not the browser you evoked them with, then when we '''echo''' out our session in any page now, this will be set as a session.  
 
|-
 
|-
 
|02:20
 
|02:20
Line 55: Line 55:
 
|-
 
|-
 
|02:28
 
|02:28
|So I'll save this as "member dot php".  
+
|So, I'll '''save''' this as "member dot php".  
 
|-
 
|-
 
|02:30
 
|02:30
|Here I'll say "echo" and I'll echo the "username session", okay?  
+
|Here I'll say '''echo''' and I'll echo the "username" session, okay?  
 
|-
 
|-
 
|02:42
 
|02:42
|In fact, I'll concatenate at the start "Welcome" and at the end, just to make it more expressive let me add an exclamation mark.  
+
|In fact, I'll concatenate at the start "Welcome" and at the end, just to make it more expressive, let me add an exclamation mark.  
 
|-
 
|-
 
|02:55
 
|02:55
|As long as we are logged in, this should run this command here, setting our session in our browser to our "username" on any other page we create.  
+
|As long as we are logged in, this should '''run''' this '''command''' here, setting our '''session''' in our browser to our "username" on any other '''page''' we create.  
 
|-
 
|-
 
|03:06
 
|03:06
Line 73: Line 73:
 
|-
 
|-
 
|03:18
 
|03:18
|So you need "session start" inside every page that you call or declare a session in.
+
|So you need "session start()" inside every page that you call or declare a '''session''' in.
 
|-
 
|-
 
|03:29
 
|03:29
Line 79: Line 79:
 
|-
 
|-
 
|03:35
 
|03:35
|I'll login with my details as "Alex" and "abc", click log in.  
+
|I'll login with my details as "Alex" and "abc", click on '''Login'''.  
 
|-
 
|-
 
|03:41
 
|03:41
|"You're in! Click here to enter the member page". Now as you can see, there is no error. I've successfully created my session.  
+
|"You're in! '''Click''' here to enter the member page". Now as you can see, there is no '''error'''. I've successfully created my '''session'''.  
 
|-
 
|-
 
|03:49
 
|03:49
Line 88: Line 88:
 
|-
 
|-
 
|03:52
 
|03:52
|Let's go back and see what I've done wrong. This should be "username".  
+
|Let's go back and see what I've done wrong. This should be "$username".  
 
|-
 
|-
 
|04:00
 
|04:00
|I'm not using any comparison here but I've put a double equals to sign here. That might be wrong.
+
|I'm not using any comparison here but I've put a double equals sign here. That might be wrong.
 
|-
 
|-
 
|04.07
 
|04.07
Line 97: Line 97:
 
|-
 
|-
 
|04:17
 
|04:17
|Login, okay, "You're in! Click here to enter the member page".  Click here and "Welcome, alex!".  
+
|Login, okay, "You're in! '''Click''' here to enter the member page".  Click here and "Welcome, alex!".  
 
|-
 
|-
 
|04:26
 
|04:26
Line 106: Line 106:
 
|-
 
|-
 
|04:32
 
|04:32
|If I go back to the member page which is "member dot php" and press enter it is still saying "alex".
+
|But if I go back to the '''member page''' which is "member dot php" and press '''Enter''', it is still saying "alex".
 
|-
 
|-
 
|04:40
 
|04:40
|And in some second-starts if I close my browser and reopen it and I go to "local host php academy" then go back to my page which is the "login" session and back to my member page I'm still logged in. okay?
+
|And in some second-starts, if I close my browser and reopen it and I go to "local host php academy" then go back to my page which is the "login session" and back to my '''member page''', I'm still logged in. okay?
 
|-
 
|-
 
|05:03
 
|05:03
|So my user is logged in. If I close the browser I am  still going to be logged in when I enter back.  
+
|So, my user is logged in. If I close the browser, I am  still going to be logged in when I enter back.  
 
|-
 
|-
 
|05:12
 
|05:12
Line 118: Line 118:
 
|-
 
|-
 
|05:19
 
|05:19
|A lot of websites to do this to keep you logged in.
+
|A lot of websites do this to keep you logged in.
 
|-
 
|-
 
|05:23
 
|05:23
|But now I want to create a log out page.  
+
|But now I want to create a log-out page.  
 
|-
 
|-
 
|05:26
 
|05:26
|To log out all we need to do is, we need to create a separate page and let's just save it as "logout dot php".  
+
|To log out, all we need to do is: we need to create a separate page and let's just '''save''' it as "logout dot php".  
 
|-
 
|-
 
|05:33
 
|05:33
|And we need to end our session here.  
+
|And we need to end our '''session''' here.  
 
|-
 
|-
 
|05:39
 
|05:39
Line 133: Line 133:
 
|-
 
|-
 
|05:46
 
|05:46
|So I'll type "session start" here. Let me confirm it once.   
+
|So I'll type "session_start()" here. Let me confirm it once.   
 
|-
 
|-
 
|05:55
 
|05:55
|Ok and then we need to say "session destroy". Sorry, not sestroy, destroy.  
+
|Ok. And then we need to say "session_ destroy()". Sorry, not sestroy, destroy.  
 
|-
 
|-
 
|06:04
 
|06:04
|If we run this page here, it will destroy our session.  
+
|If we '''run''' this page here, it will destroy our '''session'''.  
 
|-
 
|-
 
|06:08
 
|06:08
|Here I could type a friendly error message "You've been logged out. Click here to return".  
+
|Here, I could type a friendly error message "You've been logged out. Click here to return".  
 
|-
 
|-
 
|06:20
 
|06:20
|Let me create a link back to our "index dot php" page.
+
|Let me create a '''link''' back to our "index dot php" '''page'''.
 
|-
 
|-
 
|06:32
 
|06:32
|Now I'll test this again. For example, lets say.....
+
|Now I'll test this again. For example, let's say.....
 
|-
 
|-
 
|06:35
 
|06:35
|Lets put a break there. Here I'll create a link to log out.  
+
|Let's put a '''break''' there. Here I'll create a '''link''' to log-out.  
 
|-
 
|-
 
|06:41
 
|06:41
|Its important to give the link the user to our "logout  dot php" page otherwise they'll not know how to logout.
+
|It's important to give the '''link''' to the user to our "logout  dot php" page; otherwise they'll not know how to logout.
 
|-
 
|-
 
|06:50
 
|06:50
|We refresh this and it will create a log out link, to log out from the php page.  
+
|We refresh this and it will create a '''Logout''' link, to log out from the php page.  
 
|-
 
|-
 
|06:55
 
|06:55
Line 163: Line 163:
 
|-
 
|-
 
|06:59
 
|06:59
|I assume that we've been logged out. Trying to go back to our member page dot php.  
+
|I assume that we've been logged out. Trying to go back to our '''member page''' dot php.  
 
|-
 
|-
 
|07:04
 
|07:04
Line 172: Line 172:
 
|-
 
|-
 
|07:13
 
|07:13
|So, here I'll say session start then I'll say "if session and the session name which is username.
+
|So, here I'll say '''session_start()''' then I'll say '''if''' session and the session name which is 'username'.
 
|-
 
|-
 
|07:19
 
|07:19
|Next I'll echo out my data to say "Welcome" else I'll say die.  
+
|Next, I'll '''echo''' out my data to say "Welcome" else I'll say '''die()'''.  
 
|-
 
|-
 
|07:25
 
|07:25
Line 181: Line 181:
 
|-
 
|-
 
|07:45
 
|07:45
|We're saying, if this session exists or if it has been created by using a correct username and password we can echo out our friendly message to say "Welcome" otherwise kill the page and say "You must be logged in!".  
+
|We're saying: if this session exists or if it has been created by using a correct username and password, we can echo out our friendly message to say "Welcome"; otherwise kill the page and say "You must be logged in!".  
 
|-
 
|-
 
|07:55  
 
|07:55  
|So, this is all in this part of the tutorial. Let me summarise this for you.   
+
|So, this is all in this part of the tutorial. Let me summarize this for you.   
 
|-
 
|-
 
|08:04
 
|08:04
|Remember I'm not logged in.  So let me login.  
+
|Remember, I'm not logged in.  So, let me login.  
 
|-
 
|-
 
|08:06
 
|08:06
Line 193: Line 193:
 
|-
 
|-
 
|08:10
 
|08:10
|Now as we've created member dot php, press Enter.  
+
|Now, as we've created "member dot php", press '''Enter'''.  
 
|-
 
|-
 
|08:14
 
|08:14
Line 199: Line 199:
 
|-
 
|-
 
|08:16
 
|08:16
|So for example I'm going to log in but I'll not click here to go.
+
|So, for example, I'm going to log in but I'll not click here to go.
 
|-
 
|-
 
|08:22
 
|08:22
Line 205: Line 205:
 
|-
 
|-
 
|08:29
 
|08:29
|Okay so that's it for now. This is the last part of this tutorial. If you have any questions on this I'll be more than happy to help.  
+
|Okay so that's it for now. This is the last part of this tutorial. If you have any questions on this, I'll be more than happy to help.  
 
|-
 
|-
 
|08:37
 
|08:37
|This is Evan Varkey dubbing for the Spoken Tutorial Project. Bye.
+
|This is Evan Varkey, dubbing for the Spoken Tutorial Project. Bye.

Revision as of 09:38, 8 June 2015

Time Narration
00:00 Welcome to the 3rd part of our "User login" tutorial.
00:07 Here, we'll create a session in which the user can enter a page and they're allowed to be inside the page as long as they have successfully logged in.
00:16 To start any session, we will need a function which is start session.
00:25 Is it "start session" or "session start"? Let's just test it quickly.
00:34 Right, an error! So, it must be session_start(). Sorry, I was a bit confused there.
00:40 "Session start", okay? So refresh, resend and "You're in!"
00:42 We've started the session and this let's us add a session variable.
00:51 So, "You're in!". After this, I'll say "Click here to enter the secret... no, the member page." okay?
01:12 And this is going to be a link to a page called "member dot php".
01:19 Let's just recap. As long as we send the right data, we're going to say "Click here to enter the member page" which we haven't created yet.
01:30 Let me remind you here that we just created our "session_start()" here which is very important.
01:36 We're going to create a session and to do this, let me start and type here the dollar sign underscore SESSION and then in brackets, in square brackets, we will give it a session name.
01:53 I'll call it "username" and that will be equal to our username. I think I will say '$dbusername' because that's a more direct value from the database.
02:08 We have our session set.
02:10 As long as the user is in their browser, not the browser you evoked them with, then when we echo out our session in any page now, this will be set as a session.
02:20 To prove this I'll create a new page.
02:25 It'll be the "member dot php" page.
02:28 So, I'll save this as "member dot php".
02:30 Here I'll say echo and I'll echo the "username" session, okay?
02:42 In fact, I'll concatenate at the start "Welcome" and at the end, just to make it more expressive, let me add an exclamation mark.
02:55 As long as we are logged in, this should run this command here, setting our session in our browser to our "username" on any other page we create.
03:06 If this is any other page over here and you use this code to set, it will work.
03:11 You will, of course, need this function inside here, as well.
03:18 So you need "session start()" inside every page that you call or declare a session in.
03:29 There we restart. Let's go back to the main page.
03:35 I'll login with my details as "Alex" and "abc", click on Login.
03:41 "You're in! Click here to enter the member page". Now as you can see, there is no error. I've successfully created my session.
03:49 If I click here, we get "Welcome!" We have got only that. Let's see what happened.
03:52 Let's go back and see what I've done wrong. This should be "$username".
04:00 I'm not using any comparison here but I've put a double equals sign here. That might be wrong.
04.07 Now this should work. Let's go back to our "index" page and let's log in again, as we did before.
04:17 Login, okay, "You're in! Click here to enter the member page". Click here and "Welcome, alex!".
04:26 Now I'll go back to the login page.
04:28 Most people would think all that data has been lost now.
04:32 But if I go back to the member page which is "member dot php" and press Enter, it is still saying "alex".
04:40 And in some second-starts, if I close my browser and reopen it and I go to "local host php academy" then go back to my page which is the "login session" and back to my member page, I'm still logged in. okay?
05:03 So, my user is logged in. If I close the browser, I am still going to be logged in when I enter back.
05:12 This is a very useful function if you're doing this kind of logging in.
05:19 A lot of websites do this to keep you logged in.
05:23 But now I want to create a log-out page.
05:26 To log out, all we need to do is: we need to create a separate page and let's just save it as "logout dot php".
05:33 And we need to end our session here.
05:39 First of all, before we destroy our session we need to start it.
05:46 So I'll type "session_start()" here. Let me confirm it once.
05:55 Ok. And then we need to say "session_ destroy()". Sorry, not sestroy, destroy.
06:04 If we run this page here, it will destroy our session.
06:08 Here, I could type a friendly error message "You've been logged out. Click here to return".
06:20 Let me create a link back to our "index dot php" page.
06:32 Now I'll test this again. For example, let's say.....
06:35 Let's put a break there. Here I'll create a link to log-out.
06:41 It's important to give the link to the user to our "logout dot php" page; otherwise they'll not know how to logout.
06:50 We refresh this and it will create a Logout link, to log out from the php page.
06:55 Click on this and you get "You've been logged out. Click here to return."
06:59 I assume that we've been logged out. Trying to go back to our member page dot php.
07:04 We have got no variable here.
07:06 Now you don't want the users to get access to this page because they are not logged in right now.
07:13 So, here I'll say session_start() then I'll say if session and the session name which is 'username'.
07:19 Next, I'll echo out my data to say "Welcome" else I'll say die().
07:25 No! Not me - I want my page to die! So I'll say "You must be logged in".
07:45 We're saying: if this session exists or if it has been created by using a correct username and password, we can echo out our friendly message to say "Welcome"; otherwise kill the page and say "You must be logged in!".
07:55 So, this is all in this part of the tutorial. Let me summarize this for you.
08:04 Remember, I'm not logged in. So, let me login.
08:06 I am in. There's my member page. I can log out. I return here.
08:10 Now, as we've created "member dot php", press Enter.
08:14 It displays, "You must be logged in!".
08:16 So, for example, I'm going to log in but I'll not click here to go.
08:22 I'll just forward myself to "member dot php". Message has been created and I've been allowed access.
08:29 Okay so that's it for now. This is the last part of this tutorial. If you have any questions on this, I'll be more than happy to help.
08:37 This is Evan Varkey, dubbing for the Spoken Tutorial Project. Bye.

Contributors and Content Editors

Gaurav, Gyan, PoojaMoolya, Sandhya.np14