34 lines
No EOL
1.3 KiB
PHP
34 lines
No EOL
1.3 KiB
PHP
<?php // cookies.php :: Handles cookies. (Mmm, tasty!)
|
|
|
|
function checkcookies() {
|
|
global $renderer;
|
|
global $db;
|
|
global $userRepository;
|
|
$row = false;
|
|
|
|
if (isset($_COOKIE["dkgame"])) {
|
|
|
|
// COOKIE FORMAT:
|
|
// {ID} {USERNAME} {PASSWORDHASH} {REMEMBERME}
|
|
$theuser = explode(" ",$_COOKIE["dkgame"]);
|
|
$row = $userRepository->getByUsername($theuser[1]);
|
|
if ($row === null) {
|
|
$renderer->simple("Connexion error", "Invalid cookie data. Please clear cookies and log in again. (Error 1)");
|
|
}
|
|
if ($row["id"] != $theuser[0]) {
|
|
$renderer->simple("Connexion error", "Invalid cookie data. Please clear cookies and log in again. (Error 2)");
|
|
}
|
|
if (md5($row["password"] . "--" . $db->getSecretWord()) !== $theuser[2]) {
|
|
$renderer->simple("Connexion error", "Invalid cookie data. Please clear cookies and log in again. (Error 3)");
|
|
}
|
|
// If we've gotten this far, cookie should be valid, so write a new one.
|
|
$newcookie = implode(" ",$theuser);
|
|
if ($theuser[3] == 1) { $expiretime = time()+31536000; } else { $expiretime = 0; }
|
|
setcookie ("dkgame", $newcookie, $expiretime, "/", "", 0);
|
|
$userRepository->updateOnlineTime($theuser[0]);
|
|
}
|
|
|
|
return $row;
|
|
}
|
|
|
|
?>
|