Created
June 15, 2012 10:07
-
-
Save 12Rain12/2935721 to your computer and use it in GitHub Desktop.
class session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Класс работы с сессиями | |
*/ | |
class Session | |
{ | |
/** | |
* Обьект экземпляр классa Session | |
*/ | |
protected static $Session; | |
/** | |
* Имя сессии | |
*/ | |
private $sessionName = '_encrypted'; | |
/** | |
* Индефикатор работы сессии | |
*/ | |
private $running = FALSE; | |
private function __construct() | |
{ | |
} | |
public static function getInstance() | |
{ | |
if (is_null(self::$Session)) { | |
self::$Session = new Session; | |
} | |
return self::$Session; | |
} | |
/** | |
* функция старта сессии | |
*/ | |
public function start() | |
{ | |
if (!isset($_SESSION)) { | |
session_name($this->sessionName); | |
session_start(); | |
} else { | |
$sn = session_name(); | |
$_SESSION = array(); | |
$this->running = TRUE; | |
} | |
} | |
/** | |
* Возвращает значение элемента $key | |
*/ | |
public function getSession($key) | |
{ | |
if (!$this->running) $this->start(); | |
return $_SESSION[$key]; | |
} | |
/** | |
* Устанавливаем элементу $key значение $value | |
*/ | |
public function setSession($key, $value) | |
{ | |
if (!$this->running) $this->start(); | |
$_SESSION[$key] = $value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment