Starting a Session with session_start()

You need to explicitly start or resume a session unless you have changed your php.ini configuration file. By default, sessions do not start automatically. In php.ini, you will find a line containing the following:

session.auto_start = 0

By changing the value of session.auto_start to 1, you ensure that a session is initiated for every PHP document. If you don’t change this setting, you need to call the session_start() function.

PHP uses files to store session data between requests so you should also check the session.save_path directive in your php.ini file. session.save_path defines the directory on your filesystem to which session files are saved. You should ensure that it exists and that your PHP process ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.