Using session_start(); on every page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Using session_start(); on every page

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Using session_start(); on every page

Post 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.
Post Reply