Sessions in PHP is a way to preserve data for a user over multiple page loads. This function creates a session and is also used to resume a previously created session.

Unless otherwise configured, sessions will attempt to use a cookie to keep track of the user/session connection. For this reason, session_start() must be called before any output is sent (this is the behavior of cookies). The most common error that gives new comers a hard time is a result of this.

Typically, there is whitespace found at the end of some file included before the call to session_start(). This results in the dreaded “headers already sent” error. Look for new lines or spaces after the closing ?> of all files (or just leave those off).

Multiple calls to session_start() in a single script will give a notice but only the first call will do anything. The others will be ignored.

This function always returned true until PHP 5.3 where you will now get false should the session fail to start.