In PHP, do you have to declare session_start(); within a function?

Within any script, it's enough to call session_start only once. Within functions you just have to make sure that the variables are accessible (globals).

You don't need to call session_start at all, if the respective script does not need to work with the session. As long as cookies are used, the next script requiring a session will safely retrieve the session, even if the user in between called pages that didn't use the session.
 
Back
Top