AVE.CMS v3.28
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
3.6 KiB

8 years ago
<?php
5 years ago
/**
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @filesource
* @copyright © 2007-2014 AVE.cms, http://www.ave-cms.ru
*
* @license GPL v.2
*/
class AVE_Session_DB
{
public $sess_lifetime;
8 years ago
/**
5 years ago
* Хост
8 years ago
*
5 years ago
* @var string
8 years ago
*/
5 years ago
protected $db_host;
8 years ago
5 years ago
/**
* Имя пользователя
*
* @var string
*/
protected $db_user;
8 years ago
5 years ago
/**
* Пароль
*
* @var string
*/
protected $db_pass;
8 years ago
5 years ago
/**
* Имя текущей БД.
*
* @var string
*/
protected $db_dbase;
8 years ago
5 years ago
/**
* Префикс БД.
*
* @var string
*/
protected $db_prefix;
8 years ago
5 years ago
private $mysql_connect = null;
private $mysql_db = null;
8 years ago
5 years ago
/* Create a connection to a database */
function __construct()
{
// Подключаем конфигурационный файл с параметрами подключения
require (BASE_DIR . '/config/db.config.php');
$this->db_host = $config['dbhost'];
$this->db_user = $config['dbuser'];
$this->db_pass = $config['dbpass'];
$this->db_dbase = $config['dbname'];
$this->db_prefix = $config['dbpref'];
$this->sess_lifetime = (defined('SESSION_LIFETIME') && is_numeric(SESSION_LIFETIME))
? SESSION_LIFETIME
: (get_cfg_var("session.gc_maxlifetime") < 1440
? 1440
: get_cfg_var("session.gc_maxlifetime"));
if (! $this->mysql_connect = mysqli_connect ($this->db_host, $this->db_user, $this->db_pass))
{
$this->error();
6 years ago
}
8 years ago
5 years ago
if (! $this->mysql_db = mysqli_select_db ($this->mysql_connect, $this->db_dbase))
6 years ago
{
5 years ago
$this->error();
6 years ago
}
8 years ago
5 years ago
$this->mysql_connect->set_charset('utf8');
8 years ago
5 years ago
return true;
}
8 years ago
5 years ago
/* Open session */
function _open($path, $name)
{
return true;
}
8 years ago
5 years ago
/* Close session */
function _close()
{
@mysqli_query($this->mysql_connect, "DELETE FROM " . PREFIX . "_sessions WHERE expiry < '" . time() . "'");
8 years ago
5 years ago
if ($this->mysql_connect !== null)
@mysqli_close($this->mysql_connect);
8 years ago
5 years ago
return true;
}
6 years ago
5 years ago
/* Read session */
function _read($ses_id)
{
$qid = @mysqli_query($this->mysql_connect, "SELECT value, Ip FROM " . PREFIX . "_sessions WHERE sesskey = '" . $ses_id . "' AND expiry > '" . time() . "'");
6 years ago
5 years ago
if ((list($value, $ip) = @mysqli_fetch_row($qid)) && $ip == $_SERVER['REMOTE_ADDR'])
{
return $value;
8 years ago
}
5 years ago
return '';
}
8 years ago
5 years ago
/* Write new data */
function _write($ses_id, $data)
{
if (! $qid = @mysqli_query($this->mysql_connect, "INSERT INTO ".PREFIX."_sessions VALUES ('".$ses_id."', ".(time()+$this->sess_lifetime).", '".addslashes($data)."', '".$_SERVER['REMOTE_ADDR']."', FROM_UNIXTIME(expiry, '%d.%m.%Y, %H:%i:%s'))"))
6 years ago
{
5 years ago
$qid = @mysqli_query($this->mysql_connect, "UPDATE ".PREFIX."_sessions SET expiry = ".(time()+$this->sess_lifetime).", expire_datum = FROM_UNIXTIME(expiry,'%d.%m.%Y, %H:%i:%s'), value = '".addslashes($data)."', Ip = '".$_SERVER['REMOTE_ADDR']."' WHERE sesskey = '".$ses_id."' AND expiry > '".time()."'");
6 years ago
}
8 years ago
5 years ago
return $qid;
}
6 years ago
5 years ago
/* Destroy session */
function _destroy($ses_id)
{
return @mysqli_query($this->mysql_connect, "DELETE FROM ".PREFIX."_sessions WHERE sesskey = '".$ses_id."'");
}
6 years ago
5 years ago
/* Garbage collection, deletes old sessions */
function _gc($maxlifetime)
{
$session_res = @mysqli_query($this->mysql_connect, "DELETE FROM ".PREFIX."_sessions WHERE expire < (UNIX_TIMESTAMP(NOW()) - " . (int)$maxlifetime . ")");
8 years ago
5 years ago
if (!$session_res) {
return false;
}
else
{
return true;
6 years ago
}
8 years ago
}
5 years ago
function error() {
ob_start();
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
header('X-Powered-By:');
display_notice("Error connect to MySQL.");
die;
}
}
8 years ago
?>