Jump to content


Photo

PHP && Sessions


  • Please log in to reply
2 replies to this topic

#1 xExekut3x

xExekut3x

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 12 July 2013 - 12:12 AM

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.


Edited by xExekut3x, 12 July 2013 - 12:13 AM.


#2 requinix

requinix

    Transforming Moderator

  • Moderators
  • 6,226 posts
  • LocationWA

Posted 12 July 2013 - 12:41 AM

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.

#3 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,731 posts
  • LocationBonita, FL

Posted 12 July 2013 - 01:28 AM

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.
Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com