Jump to content

PHP && Sessions


xExekut3x

Recommended Posts

I'm using MySQL to store Session data. I understand that "session_start();" has to be called before anything else. Are there no exceptions? Can I not open up a database connection and pass it to my Session class before I call session_start();? I'm trying to cut down on the number of times I open up SQL connections in my script, and if I could open up just one connection per user, that would be great.

Link to comment
https://forums.phpfreaks.com/topic/280091-php-sessions/
Share on other sites

You must session_start() for PHP to do session stuff for you. If you want to manually read the session cookie, query the database, and reconstruct data, that's stupid but you can go right ahead.

 

As for opening up multiple connections, you're the one in charge of when and how that happens so just make sure you reuse (either explicitly or by passing the same information to most database drivers' connect methods) the connection for both sessions and normal usage.

Link to comment
https://forums.phpfreaks.com/topic/280091-php-sessions/#findComment-1440426
Share on other sites

I understand that "session_start();" has to be called before anything else.

Should read:

... called before anything else any output is generated.

You can do whatever you want prior to calling session_start() so long as

a) No output is generated and

b) You're not trying to use session data

 

Opening a database connection shouldn't conflict with either of the above so feel free to open the DB first, then call session_start.

Link to comment
https://forums.phpfreaks.com/topic/280091-php-sessions/#findComment-1440429
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.