Page 1 of 1

Using session_start(); on every page

Posted: Wed Sep 17, 2008 5:19 pm
by seodevhead
Hey gang,

I've been working on a website that is a compilation of various php scripts that do different things... all of which is written with php/mysql. I use a header template file that is used for every single php page I create, and that header template contains only two things.. ob_start() and session_start().

So every php script on this website has session_start() called. But only about 15-20% of the php pages (couple hundred php files total) actually use session variables. I just figured I'd let any php page I create call session_start() just in case in the future I'd need it.

Is there any real harm to calling session_start() for every php page I create? Even though I don't actually use sessions on 80% of those pages? Since I'm no pro, I just want someone to tell me that this is acceptable and not heavily frowned upon.

Thank you for all your guidance and advice. Take care.

Re: Using session_start(); on every page

Posted: Wed Sep 17, 2008 6:20 pm
by josh
There's generally nominal overhead associated with instantiating a session, Instead of manually calling the session_start() on every page call, you could create a "bootstrap" file that gets included on every page call, so if you want to add other initialization code other then session related stuff, you can keep it in one easy to update file.