How do you go about storing user sessions in MySQL. I have heard some talk about this, but I have not been able to find any tutorials and or descriptions of how this is accomplished.
Any leads and/or small examples to get me underway would be much appreciated.
Well correct me if Im wrong but storing a session in a db just means getting the SESSION ID and comparing when they come back right?
Found this in a fourm:
"You can use session_id() to get the session ID, and use that as the primary key.
Then session_encode() will give you a string to insert into the database. Do all that at the end of your script.
At the top of your script you can use session_decode() after extracting the session data from the database, it will set the variables automatically.
Alternatively, you could use session_set_save_handler() and write a few functions to do the job."
But that is, yet again, a PEAR based example. I don't want to get into a huge debate about PEAR but I can include ADODB with every one of my scripts but PEAR:: DB requires... <austinpowers>PEAR</austinpowers>... and there are a great number of servers that don't support it. Not a big deal if you are writing a personal script but if you are making an app for distribution you will be affected.
php: I use ADODB ( a database abstraction library ) and it's database session management. You might want to check it out. http://php.weblogs.com/ADODB
Last time I checked (admittedly, a while ago), ADODB creates a new database connection just for session handling. This would be fine if your were storing your sessions in a different database to your application data, but often (especially on smaller sites or shared servers) that's not the case. A number of hosts limit the number of concurrent connections you can have, so it's be nice if ADODB gave one the option to use an existing connection. (Of course, I could always write a "wrapper" to do this, but I prefer to use the Eclipse classes which I find lighter and quicker.)