2017-02-05 11:51:02 -06:00
|
|
|
<?php // cookies.php :: Handles cookies. (Mmm, tasty!)
|
|
|
|
|
2017-02-05 12:01:47 -06:00
|
|
|
// Dragon Scourge
|
|
|
|
//
|
|
|
|
// Program authors: Jamin Blount
|
|
|
|
// Copyright (C) 2007 by renderse7en
|
2017-02-05 12:02:56 -06:00
|
|
|
// Script Version 1.0 Beta 5 Build 20
|
2017-02-05 12:01:47 -06:00
|
|
|
|
|
|
|
// You may not distribute this program in any manner, modified or
|
|
|
|
// otherwise, without the express, written consent from
|
|
|
|
// renderse7en.
|
|
|
|
//
|
|
|
|
// You may make modifications, but only for your own use and
|
|
|
|
// within the confines of the Dragon Scourge License Agreement
|
|
|
|
// (see our website for that).
|
|
|
|
|
2017-02-05 11:51:02 -06:00
|
|
|
function checkcookies() {
|
|
|
|
|
|
|
|
include('config.php');
|
2017-02-05 11:58:57 -06:00
|
|
|
global $controlrow;
|
2017-02-05 11:51:02 -06:00
|
|
|
|
|
|
|
$row = false;
|
|
|
|
|
2017-02-05 11:58:57 -06:00
|
|
|
if (isset($_COOKIE[$controlrow["cookiename"]])) {
|
2017-02-05 11:51:02 -06:00
|
|
|
|
|
|
|
// COOKIE FORMAT:
|
|
|
|
// {ID} {USERNAME} {PASSWORDHASH} {REMEMBERME}
|
2017-02-05 11:58:57 -06:00
|
|
|
$theuser = explode(" ",$_COOKIE[$controlrow["cookiename"]]);
|
2017-02-05 11:51:02 -06:00
|
|
|
if (!is_numeric($theuser[0])) { err("Invalid cookie data (Error 0). Please clear cookies and log in again."); }
|
2017-02-05 11:57:55 -06:00
|
|
|
$row = dorow(doquery("SELECT * FROM <<accounts>> WHERE username='$theuser[1]' LIMIT 1"));
|
2017-02-05 11:51:02 -06:00
|
|
|
if ($row == false) { err("Invalid cookie data (Error 1). Please clear cookies and log in again."); }
|
|
|
|
if ($row["id"] != $theuser[0]) { err("Invalid cookie data (Error 2). Please clear cookies and log in again."); }
|
|
|
|
if (md5($row["password"] . "--" . $dbsettings["secretword"]) !== $theuser[2]) { err("Invalid cookie data (Error 3). Please clear cookies and log in again."); }
|
|
|
|
|
|
|
|
// 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; }
|
2017-02-05 11:58:57 -06:00
|
|
|
setcookie ($controlrow["cookiename"], $newcookie, $expiretime, "/", $controlrow["cookiedomain"], 0);
|
2017-02-05 11:51:02 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $row;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|