Write session start on 1 page or all pages?

hmwhat picture hmwhat · Aug 20, 2011 · Viewed 33.3k times · Source

All the tutorials say to put session start. They don't say if that should be in all pages on the website, or some, or only 1.

And if it's only 1 page, does it have to be the main page? Or a page with a form that I am making that puts the session ID in the database? If the visitor never visits a page with a session id but they are on the site, do they still have a session id?

Answer

theprogrammer picture theprogrammer · Aug 20, 2011

You need to put this in each page that need to access the session data before accessing (or creating) any session data.

See: http://php.net/manual/en/function.session-start.php