<?php

$rSessionTimeout = 60;

if (defined('TMP_PATH')) {
} else {
	define('TMP_PATH', '/home/xc_vm/tmp/');
}

if (session_status() != PHP_SESSION_NONE || headers_sent()) {
} else {
	session_start();
}

if (!(isset($_SESSION['hash']) && isset($_SESSION['last_activity']) && $rSessionTimeout * 60 < time() - $_SESSION['last_activity'])) {
} else {
	foreach (array('hash', 'ip', 'code', 'verify', 'last_activity') as $rKey) {
		if (!isset($_SESSION[$rKey])) {
		} else {
			unset($_SESSION[$rKey]);
		}
	}

	if (session_status() !== PHP_SESSION_NONE || headers_sent()) {
	} else {
		session_start();
	}
}

if (!isset($_SESSION['hash'])) {
	if (basename(__FILE__) == basename($_SERVER['SCRIPT_FILENAME'])) {
		echo json_encode(array('result' => false));

		exit();
	}

	if (!headers_sent()) {
		header('Location: ./login?referrer=' . urlencode(basename($_SERVER['REQUEST_URI'], '.php')));
	}

	exit();
}

if (basename(__FILE__) == basename($_SERVER['SCRIPT_FILENAME'])) {
	echo json_encode(array('result' => true));

	exit();
}

$_SESSION['last_activity'] = time();
session_write_close();
