mirror of https://github.com/avecms/AVE.cms.git
M@dD3n
5 years ago
35 changed files with 568 additions and 417 deletions
@ -1,155 +1,161 @@
|
||||
<?php |
||||
|
||||
/** |
||||
* 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; |
||||
|
||||
/** |
||||
* AVE.cms |
||||
* |
||||
* @package AVE.cms |
||||
* @version 3.x |
||||
* @filesource |
||||
* @copyright © 2007-2014 AVE.cms, http://www.ave-cms.ru |
||||
* Хост |
||||
* |
||||
* @license GPL v.2 |
||||
* @var string |
||||
*/ |
||||
protected $db_host; |
||||
|
||||
class AVE_Session_DB |
||||
{ |
||||
|
||||
public $sess_lifetime; |
||||
|
||||
/** |
||||
* Хост |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $db_host; |
||||
|
||||
/** |
||||
* Имя пользователя |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $db_user; |
||||
|
||||
/** |
||||
* Пароль |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $db_pass; |
||||
|
||||
/** |
||||
* Имя текущей БД. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $db_dbase; |
||||
|
||||
/** |
||||
* Префикс БД. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $db_prefix; |
||||
|
||||
private $mysql_connect = null; |
||||
private $mysql_db = null; |
||||
|
||||
|
||||
/* 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']; |
||||
/** |
||||
* Имя пользователя |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $db_user; |
||||
|
||||
$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")); |
||||
/** |
||||
* Пароль |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $db_pass; |
||||
|
||||
if (! $this->mysql_connect = mysqli_connect ($this->db_host, $this->db_user, $this->db_pass)) |
||||
$this->error(); |
||||
/** |
||||
* Имя текущей БД. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $db_dbase; |
||||
|
||||
if (! $this->mysql_db = mysqli_select_db ($this->mysql_connect, $this->db_dbase)) |
||||
$this->error(); |
||||
/** |
||||
* Префикс БД. |
||||
* |
||||
* @var string |
||||
*/ |
||||
protected $db_prefix; |
||||
|
||||
$this->mysql_connect->set_charset('utf8'); |
||||
private $mysql_connect = null; |
||||
private $mysql_db = null; |
||||
|
||||
return true; |
||||
/* 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(); |
||||
} |
||||
|
||||
|
||||
/* Open session */ |
||||
function _open($path, $name) |
||||
if (! $this->mysql_db = mysqli_select_db ($this->mysql_connect, $this->db_dbase)) |
||||
{ |
||||
return true; |
||||
$this->error(); |
||||
} |
||||
|
||||
$this->mysql_connect->set_charset('utf8'); |
||||
|
||||
/* Close session */ |
||||
function _close() |
||||
{ |
||||
@mysqli_query($this->mysql_connect, "DELETE FROM " . PREFIX . "_sessions WHERE expiry < '" . time() . "'"); |
||||
return true; |
||||
} |
||||
|
||||
if ($this->mysql_connect !== null) |
||||
@mysqli_close($this->mysql_connect); |
||||
/* Open session */ |
||||
function _open($path, $name) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
/* Close session */ |
||||
function _close() |
||||
{ |
||||
@mysqli_query($this->mysql_connect, "DELETE FROM " . PREFIX . "_sessions WHERE expiry < '" . time() . "'"); |
||||
|
||||
if ($this->mysql_connect !== null) |
||||
@mysqli_close($this->mysql_connect); |
||||
|
||||
/* 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() . "'"); |
||||
return true; |
||||
} |
||||
|
||||
if ((list($value, $ip) = @mysqli_fetch_row($qid)) && $ip == $_SERVER['REMOTE_ADDR']) |
||||
return $value; |
||||
/* 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() . "'"); |
||||
|
||||
return ''; |
||||
if ((list($value, $ip) = @mysqli_fetch_row($qid)) && $ip == $_SERVER['REMOTE_ADDR']) |
||||
{ |
||||
return $value; |
||||
} |
||||
|
||||
return ''; |
||||
} |
||||
|
||||
/* Write new data */ |
||||
function _write($ses_id, $data) |
||||
/* 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'))")) |
||||
{ |
||||
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'))")) |
||||
$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()."'"); |
||||
|
||||
return $qid; |
||||
$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()."'"); |
||||
} |
||||
|
||||
/* Destroy session */ |
||||
function _destroy($ses_id) |
||||
{ |
||||
return @mysqli_query($this->mysql_connect, "DELETE FROM ".PREFIX."_sessions WHERE sesskey = '".$ses_id."'"); |
||||
} |
||||
return $qid; |
||||
} |
||||
|
||||
/* 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 . ")"); |
||||
/* Destroy session */ |
||||
function _destroy($ses_id) |
||||
{ |
||||
return @mysqli_query($this->mysql_connect, "DELETE FROM ".PREFIX."_sessions WHERE sesskey = '".$ses_id."'"); |
||||
} |
||||
|
||||
if (! $session_res) |
||||
return false; |
||||
else |
||||
return true; |
||||
} |
||||
/* 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 . ")"); |
||||
|
||||
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; |
||||
if (!$session_res) { |
||||
return false; |
||||
} |
||||
else |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
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; |
||||
} |
||||
} |
||||
?> |
@ -1,119 +1,121 @@
|
||||
<?php |
||||
/* |
||||
Версия от 06.03.2018г. |
||||
|
||||
Как это работает: |
||||
1) Пользователь зашел на сайт первый раз. |
||||
2) Если есть хотя бы один параметр - сохраняет cookies |
||||
3) Если utm_history уже есть, то сохраняет данные в utm_last |
||||
4) utm_last перезаписывается при каждом новом значении, а utm_history всегда остаётся неизменной (если был передан хотя бы один параметр) |
||||
5) utm_source сохраняется всегда до закрытия браузера |
||||
*/ |
||||
class UTMCookie |
||||
{ |
||||
/* |
||||
|
||||
private $parameters = array('utm_source', 'utm_medium', 'utm_campaign'); |
||||
Версия от 06.03.2018г. |
||||
|
||||
private $utm_history = ''; |
||||
private $utm_last = ''; |
||||
private $utm_source = ''; |
||||
Как это работает: |
||||
1) Пользователь зашел на сайт первый раз. |
||||
2) Если есть хотя бы один параметр - сохраняет cookies |
||||
3) Если utm_history уже есть, то сохраняет данные в utm_last |
||||
4) utm_last перезаписывается при каждом новом значении, а utm_history всегда остаётся неизменной (если был передан хотя бы один параметр) |
||||
5) utm_source сохраняется всегда до закрытия браузера |
||||
|
||||
//Проверка параметров: Если все присутствуют - true, иначе false |
||||
private function check_parameters() |
||||
{ |
||||
//return true; //Сохранять всегда! |
||||
*/ |
||||
class UTMCookie |
||||
{ |
||||
|
||||
$return = false; |
||||
private $parameters = array('utm_source', 'utm_medium', 'utm_campaign'); |
||||
|
||||
foreach ($this->parameters as $param) |
||||
if (isset($_GET[$param]) && $_GET[$param] != '') |
||||
$return = true; |
||||
private $utm_history = ''; |
||||
private $utm_last = ''; |
||||
private $utm_source = ''; |
||||
|
||||
return $return; |
||||
} |
||||
//Проверка параметров: Если все присутствуют - true, иначе false |
||||
private function check_parameters() |
||||
{ |
||||
//return true; //Сохранять всегда! |
||||
|
||||
//Создаёт строку с параметрами вот такого вида: utm_source=test; utm_medium=none; utm_campaign=kompaniya1; |
||||
private function create_parameters() |
||||
{ |
||||
$content = ''; |
||||
foreach($this->parameters as $param){ |
||||
|
||||
if (isset($_GET[$param]) && $_GET[$param] != '') |
||||
{ |
||||
$content .= $param.'='.$_GET[$param].'; '; |
||||
|
||||
} |
||||
else |
||||
{ |
||||
$content .= $param.'=none; '; |
||||
} |
||||
} |
||||
$return = false; |
||||
|
||||
return $content; |
||||
} |
||||
foreach ($this->parameters as $param) |
||||
if (isset($_GET[$param]) && $_GET[$param] != '') |
||||
$return = true; |
||||
|
||||
//Сохраняет переданные параметры, если требуется |
||||
//Если utm_history присутствует, то сохраняет utm_last |
||||
public function save_parameters() |
||||
{ |
||||
if (isset($_GET['utm_source']) && trim($_GET['utm_source']) != '') |
||||
return $return; |
||||
} |
||||
|
||||
//Создаёт строку с параметрами вот такого вида: utm_source=test; utm_medium=none; utm_campaign=kompaniya1; |
||||
private function create_parameters() |
||||
{ |
||||
$content = ''; |
||||
foreach($this->parameters as $param){ |
||||
|
||||
if (isset($_GET[$param]) && $_GET[$param] != '') |
||||
{ |
||||
setcookie('utm_source', $_GET['utm_source']); |
||||
$content .= $param.'='.$_GET[$param].'; '; |
||||
|
||||
$this->utm_source = $_GET['utm_source']; |
||||
} |
||||
else |
||||
{ |
||||
$content .= $param.'=none; '; |
||||
} |
||||
} |
||||
|
||||
return $content; |
||||
} |
||||
|
||||
//$utm_history = ''; |
||||
//Сохраняет переданные параметры, если требуется |
||||
//Если utm_history присутствует, то сохраняет utm_last |
||||
public function save_parameters() |
||||
{ |
||||
if (isset($_GET['utm_source']) && trim($_GET['utm_source']) != '') |
||||
{ |
||||
setcookie('utm_source', $_GET['utm_source']); |
||||
|
||||
if (! isset($_COOKIE['utm_history']) || $_COOKIE['utm_history'] == '') |
||||
{ |
||||
//Отсутствует utm_history |
||||
if($this->check_parameters() == true) |
||||
{ |
||||
$this->utm_source = $_GET['utm_source']; |
||||
} |
||||
|
||||
$utm_history = $this->create_parameters(); |
||||
setcookie('utm_history', $utm_history, time()+15552000); //На 6 месяцев |
||||
setcookie('utm_last', ''); |
||||
//$utm_history = ''; |
||||
|
||||
$this->utm_history = $utm_history; |
||||
} |
||||
if (! isset($_COOKIE['utm_history']) || $_COOKIE['utm_history'] == '') |
||||
{ |
||||
//Отсутствует utm_history |
||||
if($this->check_parameters() == true) |
||||
{ |
||||
|
||||
$utm_history = $this->create_parameters(); |
||||
setcookie('utm_history', $utm_history, time()+15552000); //На 6 месяцев |
||||
setcookie('utm_last', ''); |
||||
|
||||
$this->utm_history = $utm_history; |
||||
} |
||||
else |
||||
{ |
||||
//utm_history присутствует |
||||
|
||||
$this->utm_history = $_COOKIE['utm_history']; |
||||
} |
||||
else |
||||
{ |
||||
//utm_history присутствует |
||||
|
||||
//Перезапишем utm_last, если есть данные для этого |
||||
if($this->check_parameters() == true){ |
||||
$this->utm_history = $_COOKIE['utm_history']; |
||||
|
||||
$utm_last = $this->create_parameters(); |
||||
//Перезапишем utm_last, если есть данные для этого |
||||
if($this->check_parameters() == true){ |
||||
|
||||
if($utm_last != $_COOKIE['utm_history']) |
||||
setcookie('utm_last', $utm_last, time()+15552000); //На 6 месяцев |
||||
$utm_last = $this->create_parameters(); |
||||
|
||||
$this->utm_last = $utm_last; |
||||
if($utm_last != $_COOKIE['utm_history']) |
||||
setcookie('utm_last', $utm_last, time()+15552000); //На 6 месяцев |
||||
|
||||
} |
||||
$this->utm_last = $utm_last; |
||||
|
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
//Возвращает значение cookies |
||||
public function get_value($name = '') |
||||
{ |
||||
$name = trim($name); |
||||
return true; |
||||
} |
||||
|
||||
//Возвращает значение cookies |
||||
public function get_value($name = '') |
||||
{ |
||||
$name = trim($name); |
||||
|
||||
if ($name == '' || ! in_array($name, array('utm_history', 'utm_last', 'utm_source'))) |
||||
$name = 'utm_history'; |
||||
if ($name == '' || ! in_array($name, array('utm_history', 'utm_last', 'utm_source'))) |
||||
$name = 'utm_history'; |
||||
|
||||
if (isset($this->$name) && $this->$name != '') |
||||
return $this->$name; |
||||
if (isset($this->$name) && $this->$name != '') |
||||
return $this->$name; |
||||
|
||||
return isset($_COOKIE[$name]) ? $_COOKIE[$name] : ''; |
||||
} |
||||
return isset($_COOKIE[$name]) ? $_COOKIE[$name] : ''; |
||||
} |
||||
} |
||||
?> |
Loading…
Reference in new issue