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

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Add page access control

Add page access control

- [Instructor] Now that we have the ability for users to log in and log out and we're able to remember in our session whether or not they've logged in or not, we're able to now add access control to our pages. That is, that we can restrict the pages in our staff area to only allow logged in users to see them. The way we can do that is just simply to go to one of our staff area pages like index.php and right here at the top, we can just check to see. Put php tags and we'll just test to see if not dollar sign session is logged in. Then I'm going to redirect to url_for staff/login.php. And if they're not for some reason, then let's just do nothing, let the rest of the page proceed. So that's it, that's the process. It's going to check and see if the session says that the user is logged in. If they're not, then it will redirect them. If so, then they'll do nothing. Let's save it and try it out. Now at the…

Contents