Файл: app/functions/user.func.php
Строк: 48
<?php
# Author: Oleg Kulaga (Cyber_Shot);
# Package: WGame Engine;
# Version: 0.1;
if (!defined("APP")) die("Access Denied");
function user_checkAuthStatus()
{
if (!empty($_SESSION['userId']) &&
!empty($_SESSION['userSession']) &&
!empty($_COOKIE['userId']))
{
if (is_numeric($_SESSION['userId']) &&
is_numeric($_COOKIE['userId']))
{
if ($_SESSION['userId'] == $_COOKIE['userId'])
{
$check = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ". USERS ." WHERE `id` = ?", [$_SESSION['userId']]);
if (!empty($check))
{
$profile = DB::$dbs->queryFetch("SELECT `session`, `sessionLifeTime` FROM ". USERS ." WHERE `id` = ?", [$_SESSION['userId']]);
if ($_SESSION['userSession'] == $profile['session'])
{
if ((int)$profile['sessionLifeTime'] > $_SERVER['REQUEST_TIME'])
{
return false;
}
else
{
user_unsetUser();
}
}
else
{
user_unsetUser();
}
}
else
{
user_unsetUser();
}
}
else
{
user_unsetUser();
}
}
else
{
user_unsetUser();
}
}
else
{
user_unsetUser();
}
}
function user_unsetUser()
{
if (!empty($_SESSION['userId']))
{
unset($_SESSION['userId']);
}
if (!empty($_SESSION['userSession']))
{
unset($_SESSION['userSession']);
}
if (!empty($_COOKIE['userId']))
{
setcookie("userId", "", $_SERVER['REQUEST_TIME'] - 60, "/");
}
}
function user_auth($code = null)
{
user_checkAuthStatus();
if (empty($code))
{
if (!empty($_SESSION['userId']))
{
header("Location: ". DS.HOME.DS."wgame.main");
exit();
}
else
{
return false;
}
}
else if (!empty($code))
{
if (empty($_SESSION['userId']))
{
header("Location: ".DS.HOME.DS."wgame.index");
exit();
}
else
{
return false;
}
}
}
function user_newSession()
{
return md5($_SERVER['REQUEST_TIME'] . rand(1111, 9999) . uniqid());
}