From the course: PHP: Object-Oriented Programming with Databases

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Define a session class

Define a session class - PHP Tutorial

From the course: PHP: Object-Oriented Programming with Databases

Start my 1-month free trial

Define a session class

- [Instructor] In this movie, we're going to define a new class called session. And we're going to use it to help us manage our php sessions. We're mostly going to use it so that we can keep track of whether a user is logged in in the session or not. Let's remember that the way that we're keeping track of a user being logged in, is that we're going to store their id in the session. So for example, we have a function called log_in. We pass in an id, and it sets a variable in the session and then we can keep track of that variable from then on. On all subsequent page loads, we can check that variable and see if it's been set, we know the user is logged in. So we have another function called is_logged_in that will report back whether it's set or not. And then when we want the user to log out, we simply unset that variable. So that variable acts like a hand stamp, letting us know on each of the subsequent page requests after logging in, we know this user is already logged in and we don't…

Contents