New implementation of cookie

This commit is contained in:
Roman Kelesidis 2023-03-05 15:15:39 +07:00
parent 916f4e0178
commit e6e85db062
3 changed files with 23 additions and 7 deletions

View file

@ -1,5 +1,6 @@
{
"require": {
"symfony/polyfill": "*"
"symfony/polyfill": "*",
"delight-im/cookie": "^3.4"
}
}

View file

@ -68,6 +68,7 @@
'iptables' => 'iptables_block', // Файл правил для FireWall (блокировка на уровне оборудования) (/root/_FILE_)
'cron_key' => 'CRONKEY', // Ключ для cron.php
'cron_taskset' => '0', // Ядро, на котором запускать cron.php (уставновить отличный от нуля, если на VDS больше 1 ядра/потока)
'cookie_same_site' => 'Lax', // Lax, None, Strict | https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
// Кеш (кол-во секунд)
'mcache_server_mon' => 2, // Мониторинг (онлайн, название, карта)

View file

@ -4,6 +4,18 @@
class sys
{
public static function isSecure() {
$is_secure = false;
if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
$is_secure = true;
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
$is_secure = true;
}
return $is_secure;
}
public static function url($all = true)
{
if($_SERVER['REQUEST_URI'] == '/')
@ -429,8 +441,10 @@
public static function cookie($name, $value, $expires)
{
global $cfg;
$expires = time() + ($expires * 86400);
setcookie($name, $value, $expires, "/", $_SERVER['HTTP_HOST'], true);
\Delight\Cookie\Cookie::setcookie($name, $value, $expires, '/', $cfg['url'], self::isSecure(), true, $cfg['cookie_same_site']);
}
public static function auth()