<?php
require_once('config.php');
if($_SERVER['REQUEST_METHOD']!=='POST'||!isset($_POST['csrf'])||!hash_equals($_SESSION['csrf']??'',$_POST['csrf'])){
header("Location:".($applicationBaseDir??'/').(isset($_POST['csrf'])?'login.php':'index.php'));exit;
}
if(!empty($_COOKIE['REMEMBER_TOKEN'])){
$t=hash('sha256',$_COOKIE['REMEMBER_TOKEN']);
if(is_file($f=ABSPATH.'data/remember/'.$t))@unlink($f);
setcookie('REMEMBER_TOKEN','',time()-3600,'/','',true,true);
}
$_SESSION=[];
if(ini_get('session.use_cookies')){
$p=session_get_cookie_params();
setcookie(session_name(),'',['expires'=>time()-42000,'path'=>$p['path'],'domain'=>$p['domain'],'secure'=>$p['secure'],'httponly'=>$p['httponly'],'samesite'=>$p['samesite']??'Lax']);
}
session_destroy();
header("Location:".($applicationBaseDir??'/')."login.php");exit;
