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.

142 lines
2.8 KiB

8 years ago
<?php
7 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
8 years ago
{
7 years ago
public $sess_lifetime;
8 years ago
7 years ago
function __construct()
{
ini_set('session.save_handler', 'user');
8 years ago
7 years ago
$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"));
8 years ago
7 years ago
return true;
}
8 years ago
7 years ago
/* Open session */
function _open($sess_save_path, $session_name)
{
global $sess_save_path, $sess_session_name;
8 years ago
7 years ago
$sess_save_path = BASE_DIR . '/tmp/session';
$sess_session_name = $session_name;
8 years ago
7 years ago
return true;
8 years ago
}
7 years ago
/* Close session */
function _close()
8 years ago
{
7 years ago
$this->_gc($this->sess_lifetime);
return true;
8 years ago
}
7 years ago
/* Read session */
function _read($id)
{
global $sess_save_path, $sess_session_name, $sess_session_id;
8 years ago
7 years ago
$sess_session_id = $id;
$sess_file = $this->_folder() . '/' . $id . '.sess';
8 years ago
7 years ago
if (!file_exists($sess_file)) return "";
8 years ago
7 years ago
if ($fp = @fopen($sess_file, "r"))
{
$sess_data = fread($fp, filesize($sess_file));
return($sess_data);
}
else
{
return '';
}
8 years ago
}
7 years ago
/* Write new data */
function _write ($id, $sess_data)
8 years ago
{
7 years ago
global $sess_save_path, $sess_session_name, $sess_session_id;
8 years ago
7 years ago
$sess_session_id = $id;
$sess_file = $this->_folder() . '/' . $id . '.sess';
8 years ago
7 years ago
if(!file_exists($this->_folder()))
mkdir($this->_folder(), 0777, true);
8 years ago
7 years ago
if ($fp = @fopen($sess_file, "w"))
{
return fwrite($fp, $sess_data);
}
else
{
return false;
}
}
8 years ago
7 years ago
/* Destroy session */
function _destroy ($id)
{
global $sess_save_path, $sess_session_name, $sess_session_id;
8 years ago
7 years ago
$sess_session_id = $id;
$sess_dir = $this->_folder();
$sess_file = $sess_dir . '/' . $id . '.sess';
8 years ago
7 years ago
return @unlink($sess_file);
}
8 years ago
7 years ago
/* Garbage collection, deletes old sessions */
function _gc ($maxlifetime)
{
global $sess_save_path, $sess_session_id;
8 years ago
7 years ago
$this->_clear($sess_save_path, 'sess', $maxlifetime);
8 years ago
7 years ago
return true;
8 years ago
}
7 years ago
function _clear($dir, $mask, $maxlifetime)
{
foreach(glob($dir . '/*') as $filename)
{
if (strtolower(substr($filename, strlen($filename) - strlen($mask), strlen($mask))) == strtolower($mask))
{
if ((filemtime($filename) + $maxlifetime) < time())
@unlink($filename);
}
if (is_dir($filename))
if (! count(glob($filename.'/*')))
@rmdir($filename);
self::_clear($filename, $mask, $maxlifetime);
}
}
8 years ago
7 years ago
function _folder()
{
global $sess_session_id, $sess_save_path;
8 years ago
7 years ago
return $sess_save_path . '/' . mb_substr($sess_session_id, 0, 3);
}
8 years ago
7 years ago
function __destruct ()
{
register_shutdown_function('session_write_close');
}
}
8 years ago
?>