r/PHPhelp • u/[deleted] • Feb 09 '19
Does 'session_start();' cascade into other php files or do I have to declare it every time?
I am working on a project with no framework. Bare bones php 7.
Using sessions quite a bit.
Do I have to 'session_start();' at the top of every PHP page I want to use sessions in, or can I just declare it once at top of the index or controller file and the 'session_start(); will cascade into other files.
8
Upvotes
6
u/RandyHoward Feb 09 '19
If I'm not working in a framework, I tend to throw that in the top of any file that needs the session. It'll ensure you start a session if there is none, and won't try to start one if one exists.