/** * Given an ID, and some data, save it into `tbl_sessions`. This uses * the ID as a unique key, and will override any existing data. If the * `$data` is deemed to be empty, no row will be saved in the database * unless there is an existing row. * * @param string $id * The ID of the Session, usually a hash * @param string $data * The Session information, usually a serialized object of * `$_SESSION[Cookie->_index]` * @throws DatabaseException * @return boolean * True if the Session information was saved successfully, false otherwise */ public static function write($id, $data) { // Only prevent this record from saving if there isn't already a record // in the database. This prevents empty Sessions from being created, but // allows them to be nulled. $session_data = Session::read($id); if (is_null($session_data)) { $empty = true; $unserialized_data = Session::unserialize($session_data); foreach ($unserialized_data as $d) { if (!empty($d)) { $empty = false; } } if ($empty) { return false; } } $fields = array('session' => $id, 'session_expires' => time(), 'session_data' => $data); return Symphony::Database()->insert($fields, 'tbl_sessions', true); }