$session_id, ) ); list ($sess_data) = $smcFunc['db_fetch_row']($result); $smcFunc['db_free_result']($result); return $sess_data != null ? $sess_data : ''; } /** * Implementation of sessionWrite() replacing the standard write handler. * * @param string $session_id The session ID * @param string $data The data to write to the session * @return boolean Whether the info was successfully written */ function sessionWrite($session_id, $data) { global $smcFunc, $db_connection, $db_server, $db_name, $db_user, $db_passwd; global $db_prefix, $db_persist, $db_port, $db_mb4; if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) return false; // php < 7.0 need this if (empty($db_connection)) { $db_options = array(); // Add in the port if needed if (!empty($db_port)) $db_options['port'] = $db_port; if (!empty($db_mb4)) $db_options['db_mb4'] = $db_mb4; $options = array_merge($db_options, array('persist' => $db_persist, 'dont_select_db' => SMF == 'SSI')); $db_connection = smf_db_initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $options); } // If an insert fails due to a dupe, replace the existing session... $session_update = $smcFunc['db_insert']('replace', '{db_prefix}sessions', array('session_id' => 'string', 'data' => 'string', 'last_update' => 'int'), array($session_id, $data, time()), array('session_id') ); return ($smcFunc['db_affected_rows']() == 0 ? false : true); } /** * Implementation of sessionDestroy() replacing the standard destroy handler. * * @param string $session_id The session ID * @return boolean Whether the session was successfully destroyed */ function sessionDestroy($session_id) { global $smcFunc; if (preg_match('~^[A-Za-z0-9,-]{16,64}$~', $session_id) == 0) return false; // Just delete the row... $smcFunc['db_query']('', ' DELETE FROM {db_prefix}sessions WHERE session_id = {string:session_id}', array( 'session_id' => $session_id, ) ); return true; } /** * Implementation of sessionGC() replacing the standard gc handler. * Callback for garbage collection. * * @param int $max_lifetime The maximum lifetime (in seconds) - prevents deleting of sessions older than this * @return boolean Whether the option was successful */ function sessionGC($max_lifetime) { global $modSettings, $smcFunc; // Just set to the default or lower? Ignore it for a higher value. (hopefully) if (!empty($modSettings['databaseSession_lifetime']) && ($max_lifetime <= 1440 || $modSettings['databaseSession_lifetime'] > $max_lifetime)) $max_lifetime = max($modSettings['databaseSession_lifetime'], 60); // Clean up after yerself ;). $session_update = $smcFunc['db_query']('', ' DELETE FROM {db_prefix}sessions WHERE last_update < {int:last_update}', array( 'last_update' => time() - $max_lifetime, ) ); return ($smcFunc['db_affected_rows']() == 0 ? false : true); } ?>