18 require_once SQ_CORE_PACKAGE_PATH.
'/system/session_handling/session_handler/session_handler.inc';
44 parent::__construct();
60 public static function init()
63 $domain = strip_url(sq_web_path(
'root_url'), TRUE);
64 $pos = strpos($domain,
'/');
67 $path = substr($domain, $pos);
68 $domain = substr($domain, 0, $pos);
73 $domain = preg_replace(
'|:\d+$|',
'', $domain);
76 if (current_protocol() ===
'https' && (defined(
'SQ_CONF_COOKIE_OPTION_SECURE') && SQ_CONF_COOKIE_OPTION_SECURE)) $secure = TRUE;
79 $php_version_suits = (version_compare(PHP_VERSION,
'5.2.0') >= 0);
80 if ($php_version_suits && (defined(
'SQ_CONF_COOKIE_OPTION_HTTP_ONLY') && SQ_CONF_COOKIE_OPTION_HTTP_ONLY)) $http_only = TRUE;
83 session_module_name(
'files');
84 if ($php_version_suits) {
85 session_set_cookie_params(0, $path, $domain, $secure, $http_only);
87 session_set_cookie_params(0, $path, $domain, $secure);
89 session_name(
'SQ_SYSTEM_SESSION');
94 if (!SQ_CONF_USE_DEFAULT_SESSION_SAVE_PATH) {
95 if (SQ_CONF_CUSTOM_SESSION_SAVE_PATH !==
'') {
96 $cache_path = SQ_CONF_CUSTOM_SESSION_SAVE_PATH;
98 $cache_path = SQ_CACHE_PATH;
101 session_save_path($cache_path);
120 $session_file = session_save_path().
'/sess_'.$session_id;
122 $session_str = file_get_contents($session_file);
124 $parts = preg_split(
'/\w+\|/', $session_str, -1, PREG_SPLIT_OFFSET_CAPTURE);
125 $session_arr = Array();
127 for ($i = 0; $i < count($parts); $i++) {
128 if ($i == count($parts) - 1)
continue;
129 $offset = $parts[$i][1] + strlen($parts[$i][0]);
130 $len = $parts[$i + 1][1] - 1 - $offset;
132 $key = substr($session_str, $offset, $len);
133 $session_arr[$key] = unserialize($parts[$i + 1][0]);
151 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
152 $session_file = session_save_path().
'/sess_'.$session_id;
154 if (!file_exists($session_file)) {
155 trigger_localised_error(
'CORE0072', E_USER_WARNING, $session_file);
159 if (!is_array($session_contents)) {
160 trigger_localised_error(
'CORE0004', E_USER_WARNING, gettype($session_contents));
165 foreach ($session_contents as $key => $val) {
166 $session_str .= $key.
'|'.serialize($val);
169 if (!string_to_file($session_str, $session_file)) {
170 trigger_localised_error(
'CORE0021', E_USER_WARNING, $session_file);
187 $session_file = session_save_path().
'/sess_'.$session_id;
188 return file_exists($session_file);
207 $pri_sess = self::unserialiseSession($pri_sessionid);
209 if (!is_array($pri_sess)) {
211 trigger_localised_error(
'CORE0071', E_USER_ERROR);
215 $pri_timestamp = array_get_index($pri_sess,
'SQ_SESSION_TIMESTAMP', -1);
216 $sec_timestamp = array_get_index($_SESSION,
'SQ_SESSION_TIMESTAMP', -1);
217 $pri_login_key = array_get_index($pri_sess,
'SQ_LOGIN_KEY', NULL);
218 $sec_login_key = array_get_index($_SESSION,
'SQ_LOGIN_KEY', NULL);
221 if ($pri_timestamp > $sec_timestamp || $pri_timestamp == -1) {
223 $_SESSION = $pri_sess;
226 $pri_sess = $_SESSION;
230 $pri_sess[
'SQ_SESSION_TIMESTAMP'] = $now;
231 $_SESSION[
'SQ_SESSION_TIMESTAMP'] = $now;
234 if (!is_null($pri_login_key)) {
235 $pri_sess[
'SQ_LOGIN_KEY'] = $pri_login_key;
237 if (!is_null($sec_login_key)) {
238 $_SESSION[
'SQ_LOGIN_KEY'] = $sec_login_key;
244 $_SESSION[
'PRIMARY_SESSIONID'] = $pri_sessionid;
245 $pri_sess[
'PRIMARY_SESSIONID'] = $pri_sessionid;
248 if (!self::serialiseSession($pri_sessionid, $pri_sess)) {
249 trigger_localised_error(
'CORE0020', E_USER_ERROR);