PHP - Storing Session in a Database PHP - Storing Session in a Database apache apache

PHP - Storing Session in a Database


The function you're using will interrupt the normal session function and insert your code in to act, then carry on with other internal functions.

In the functions where you aren't really doing anything session-wise (things like '_open' and '_close'), you need return something to carry on the command or it will just die right there.

Example:

function _open($save_path, $session_name){        global $con;    connect();    return true; //Do nothing but carry on} function _close(){      global $con;      //mysql_close();    return true; //Do nothing but carry on}


Really this is not the answer to your question, but if you need really high availability I can suggest that storing sessions in mysql is not a good method.

A better practice: Put your sessions in memcache. Memcache server it's easy to install. Memcache client is easy to install and php support storing session in memcache without programming!!! Memcache store data in memory, not in disk and it's faster.

Here you can view a good post about this: http://kevin.vanzonneveld.net/techblog/article/enhance_php_session_management/

Luck!!


How come you can't use cookies? and just have the script check if the cookies is present then read the value's from there. Unless security is an issue .. I suggest cookies over sessions for cheap scalability ..Writing session's in the database won't be good and will probably result in expensive queries being ran for no reason.