Write session start on 1 page or all pages?
You need to put this in each page that need to access the session data before accessing (or creating) any session data.
Just for a matter of completeness you can choose to write session_start();
in all pages, in just one or in none of them. Let me explain this.
You need to start session in every script where you need access to $_SESSION
variable but instead of putting session_start();
in every single script you can create a file headers.php and put there all your repetitive code including session_start();
If everything in your application needs access to $_SESSION
you can forget the use of session_start();
simply setting session.auto_start = 1
in your php.ini file. You will be able to access $_SESSION
without writing session_start();
before.
Anything that is going to access Session variables needs to start the session.
So unless you have a php page that is non-dependent on the session than every page needs it.