Port entirely to a MVC-like pattern #37
1 changed files with 12 additions and 11 deletions
|
@ -1,28 +1,29 @@
|
||||||
<?php // cookies.php :: Handles cookies. (Mmm, tasty!)
|
<?php // cookies.php :: Handles cookies. (Mmm, tasty!)
|
||||||
|
|
||||||
function checkcookies() {
|
function checkcookies() {
|
||||||
|
global $renderer;
|
||||||
include('config.php');
|
|
||||||
|
|
||||||
$row = false;
|
$row = false;
|
||||||
|
|
||||||
if (isset($_COOKIE["dkgame"])) {
|
if (isset($_COOKIE["dkgame"])) {
|
||||||
|
|
||||||
// COOKIE FORMAT:
|
// COOKIE FORMAT:
|
||||||
// {ID} {USERNAME} {PASSWORDHASH} {REMEMBERME}
|
// {ID} {USERNAME} {PASSWORDHASH} {REMEMBERME}
|
||||||
$theuser = explode(" ",$_COOKIE["dkgame"]);
|
$theuser = explode(" ",$_COOKIE["dkgame"]);
|
||||||
$query = doquery("SELECT * FROM {{table}} WHERE username='$theuser[1]'", "users");
|
$query = doquery("SELECT * FROM {{table}} WHERE username='$theuser[1]'", "users");
|
||||||
if (mysqli_num_rows($query) != 1) { die("Invalid cookie data (Error 1). Please clear cookies and log in again."); }
|
if (mysqli_num_rows($query) != 1) {
|
||||||
|
$renderer->simple("Connexion error", "Invalid cookie data. Please clear cookies and log in again. (Error 1)");
|
||||||
|
}
|
||||||
$row = mysqli_fetch_array($query);
|
$row = mysqli_fetch_array($query);
|
||||||
if ($row["id"] != $theuser[0]) { die("Invalid cookie data (Error 2). Please clear cookies and log in again."); }
|
if ($row["id"] != $theuser[0]) {
|
||||||
if (md5($row["password"] . "--" . $dbsettings["secretword"]) !== $theuser[2]) { die("Invalid cookie data (Error 3). Please clear cookies and log in again."); }
|
$renderer->simple("Connexion error", "Invalid cookie data. Please clear cookies and log in again. (Error 2)");
|
||||||
|
}
|
||||||
|
if (md5($row["password"] . "--" . $dbsettings["secretword"]) !== $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.
|
// If we've gotten this far, cookie should be valid, so write a new one.
|
||||||
$newcookie = implode(" ",$theuser);
|
$newcookie = implode(" ",$theuser);
|
||||||
if ($theuser[3] == 1) { $expiretime = time()+31536000; } else { $expiretime = 0; }
|
if ($theuser[3] == 1) { $expiretime = time()+31536000; } else { $expiretime = 0; }
|
||||||
setcookie ("dkgame", $newcookie, $expiretime, "/", "", 0);
|
setcookie ("dkgame", $newcookie, $expiretime, "/", "", 0);
|
||||||
$onlinequery = doquery("UPDATE {{table}} SET onlinetime=NOW() WHERE id='$theuser[0]' LIMIT 1", "users");
|
$onlinequery = doquery("UPDATE {{table}} SET onlinetime=NOW() WHERE id='$theuser[0]' LIMIT 1", "users");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
|
|
Loading…
Add table
Reference in a new issue