From the course: PHP Tips, Tricks, and Techniques

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Set a time limit on a session

Set a time limit on a session

- [David] Hi, I'm David Powers. And welcome to this week's edition of PHP Tips, Tricks, and Techniques designed to help you become a smarter, more productive PHP developer. The question I've often been asked is how to set a time limit to a session, so that's what we'll look at. The exercise files for this video contain a basic example of using sessions, with a login form, and a couple of password protected pages. Before looking at the script, let's consider why it's a good idea to set a time limit to a session. By default, PHP sessions data can be garbage collected after 24 minutes of inactivity. But PHP garbage collection is unpredictable. So session data can hang around for a long time. And because it's stored in plain text, sensitive information could be harvested by a malicious attacker, if the session isn't explicitly terminated. So let's take a look at the script now. In login.php, I've got a simple login form, and for demonstration purposes, the login script uses a fixed…

Contents