Skip to content

Instantly share code, notes, and snippets.

@12Rain12
Created June 15, 2012 10:07
Show Gist options
  • Save 12Rain12/2935721 to your computer and use it in GitHub Desktop.
Save 12Rain12/2935721 to your computer and use it in GitHub Desktop.
class session
<?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