| Server IP : 37.9.174.138 / Your IP : 216.73.216.117 Web Server : Apache System : Linux vps6.backend.sk 6.12.100+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.100-1 (2026-07-30) x86_64 User : ftpuser ( 1001) PHP Version : 8.4.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/ttjs.cz/dev/app/classes/ |
Upload File : |
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace app\classes;
/**
* Description of CookieUser
*
* @author pegas
*/
class CookieUser extends \app\classes\PDOElement {
protected static $loggedUser = NULL;
CONST VALIDITY_HOURS = 48;
CONST VALIDITY_REFRESH_HOURS = 8;
public function __construct($id, $tokenAsId = false, $timeCheck = false, $state = \app\constants\State::DISABLED) {
parent::__construct($id, "visitors", array($tokenAsId ? "token" : "id" => $id, "state" => $state), $tokenAsId ? "token" : "id", " state=:state " . ($timeCheck ? " AND valid_until > CURDATE()" : ""));
}
/**
* @return CookieUser
*/
public static function getLoggedUser() {
$class = get_called_class();
if (self::$loggedUser === NULL || !(self::$loggedUser instanceof $class)) {
self::loadCookieUser();
}
return self::$loggedUser;
}
public function toArray($exclude = array()) {
$exclude = $exclude + array("token", "folder");
return parent::toArray($exclude);
}
public function destructLoggedUser() {
self::$loggedUser = NULL;
}
protected static function newCookieUser() {
sleep(2);
$token = getUniqueId();
$folder = getUniqueId();
$valid = date("Y-m-d H:i:s", strtotime("+ " . self::VALIDITY_HOURS . " hours"));
$db = PDODatabase::getInstance();
try {
$db->addRecord("visitors", array(
"token" => $token,
"init_ip" => get_ip_address(),
"valid_until" => $valid,
"folder" => $folder,
"state" => \app\constants\State::DISABLED
));
setcookie("visitor", $token, strtotime($valid), "/");
$_COOKIE["visitor"] = $token;
mkdir(DOCUMENT_ROOT . "uploads/settlements/" . $folder);
$class = get_called_class();
self::$loggedUser = new $class($token, true, true);
} catch (\Exception $ex) {
self::newCookieUser();
}
}
protected static function loadCookieUser() {
try {
$class = get_called_class();
self::$loggedUser = new $class(convertToNonHtmlTags($_COOKIE["visitor"]), true, true);
if (strtotime(self::$loggedUser->_get("valid_until")) - time() < self::VALIDITY_REFRESH_HOURS * 60 * 60) {
$valid = date("Y-m-d H:i:s", strtotime("+ " . self::VALIDITY_HOURS . " hours"));
self::$loggedUser->update(array(
"valid_until" => $valid
));
self::$loggedUser->_set("valid_until", $valid);
setcookie("visitor", self::$loggedUser->_get("token"), strtotime($valid), "/");
}
} catch (\Exception $ex) {
self::newCookieUser();
}
}
}