From 6e0f3022498eadd3d57170d3625bdf2e5a7a2079 Mon Sep 17 00:00:00 2001 From: pzinovkin Date: Tue, 27 Apr 2010 19:14:43 +0000 Subject: [PATCH] Session autostart, #16 git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@143 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- app/FrontController.php | 1 - session/Session.php | 26 +++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/FrontController.php b/app/FrontController.php index 689025c..6142f2e 100644 --- a/app/FrontController.php +++ b/app/FrontController.php @@ -32,7 +32,6 @@ class FrontController private function __construct() { ErrorHandler::init(); - Session::start(); if (DEBUG == true) { Profiler::getInstance()->start(); } diff --git a/session/Session.php b/session/Session.php index b658fd3..96546b2 100644 --- a/session/Session.php +++ b/session/Session.php @@ -42,6 +42,13 @@ class Session */ public static function get($key = null, $default = null) { + if (!self::$started) { + if (self::isExists()) { + self::start(); + } else { + return $default; + } + } if (null === $key) { return $_SESSION; } @@ -57,6 +64,9 @@ class Session */ public static function set($spec, $value = null) { + if (!self::$started) { + self::start(); + } if (is_array($spec)) { foreach ($spec as $key => $value) { self::set($key, $value); @@ -73,6 +83,13 @@ class Session */ public static function del($key) { + if (!self::$started) { + if (self::isExists()) { + self::start(); + } else { + return; + } + } if (isset($_SESSION[$key])) { unset($_SESSION[$key]); } @@ -141,7 +158,7 @@ class Session public static function isExists() { - if (ini_get('session.use_cookies') == '1' && isset($COOKIE[session_name()])) { + if (isset($_COOKIE[session_name()])) { return true; } return false; @@ -149,6 +166,9 @@ class Session public static function start() { + if (self::$started) { + return; + } self::$started = true; session_start(); self::regenerateId(); @@ -188,7 +208,7 @@ class Session */ public static function expireSessionCookie() { - if (isset($COOKIE[session_name()])) { + if (isset($_COOKIE[session_name()])) { $params = session_get_cookie_params(); setcookie( session_name(), @@ -200,4 +220,4 @@ class Session ); } } -} \ No newline at end of file +}