<?php
if (!defined('SECURITY_WSCMS')) die('Прямой вызов модуля запрещен!');
# Движок wscms для браузерных игр
# Николай Довгопол, By wearnings
# vk.com/id566856271, +38(094)890-5144
class core {
# Генерация защиты от CSRF
public function gen_csrf_secure(){
$time = time();
$new_key = $time.'_'.md5($this -> user -> ip.$this -> cfg -> main['secury'].$time);
if(!isset($_COOKIE['secure'])){
setcookie("secure", $new_key, time()+$this -> csrf_time, '/');
return $new_key; }
$cookie = explode('_', $_COOKIE['secure']);
$old_time = intval($cookie[0]);
$old_key = md5($this -> user -> ip.$this -> cfg -> main['secury'].$old_time);
if(!isset($cookie[1]) || $cookie[1] !== $old_key || ($old_time+$this->csrf_time)<$time){
setcookie("secure", $new_key, time()+$this->csrf_time, '/');
return $new_key; }
return $_COOKIE['secure'];
}
}