Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

An Introduction To PHP Sessions

When Do Sessions Expire?

The default behaviour for sessions is to keep a session open indefinitely and only to expire a session when the browser is closed. This behaviour can be changed in the php.ini file by altering the line:

Listing 22 Keeping a session alive indefinitely (listing-22.txt)
session.cookie_lifetime = 0

If you wanted the session to finish in 5 minutes you would set this to:

Listing 23 Keeping a session alive for five minutes (listing-23.txt)
session.cookie_lifetime = 300

Remember to restart your web server after making this change.

In This Article