Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - Storing Session in a Database
    primarykey
    data
    text
    <p>Hey Guys, I am setting up a EC2 cluster with a load balancer. I have seperate DB server which has mysql running on it. I have 3 webservers running, mostly for high availability, and of course its round-robin load balancing it seems, so every page you go to you get a different server which looses your session.</p> <p>I am trying to setup PHP to store it in the DB. I have setup a table, and setup all the functions (open,close,etc). and I have set:</p> <pre><code>session_set_save_handler('_open', '_close', '_read', '_write', '_destroy', '_clean'); </code></pre> <p>But when I login or anything on the site I check the table and nothing has been written. I am not sure If i need to change something in the php.ini file. If so what is the value to change?</p> <p>Thanks!!</p> <p>EDIT: functions:</p> <pre><code>function _open(){ global $con; connect(); } function _close(){ global $con; //mysql_close(); } function _read($id){ global $con; $id = mysql_real_escape_string($id); $sql = "SELECT data FROM sessions WHERE id = '$id'"; if ($result = mysql_query($sql, $con)) { if (mysql_num_rows($result)) { $record = mysql_fetch_assoc($result); return $record['data']; } } return ''; } function _write($id, $data) { global $con; $access = time(); $id = mysql_real_escape_string($id); $access = mysql_real_escape_string($access); $data = mysql_real_escape_string($data); $sql = "REPLACE INTO sessions VALUES ('$id', '$access', '$data')"; return mysql_query($sql, $con); } function _destroy($id) { global $con; $id = mysql_real_escape_string($id); $sql = "DELETE FROM sessions WHERE id = '$id'"; return mysql_query($sql, $con); } function _clean($max) { global $con; $old = time() - $max; $old = mysql_real_escape_string($old); $sql = "DELETE FROM sessions WHERE access &lt; '$old'"; return mysql_query($sql, $con); } session_set_save_handler('_open', '_close', '_read', '_write', '_destroy', '_clean'); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload