forked from perberos/dragon-knight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
40 lines (28 loc) · 1.19 KB
/
login.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php // login.php :: Handles logins and cookies.
include('lib.php');
if (isset($_GET["do"])) {
if ($_GET["do"] == "login") { login(); }
elseif ($_GET["do"] == "logout") { logout(); }
}
function login() {
global $dbsettings;
$link = opendb();
if (isset($_POST["submit"])) {
$query = doquery("SELECT * FROM {{table}} WHERE username='". escape_string ($_POST["username"]) ."' AND password='".md5($_POST["password"])."' LIMIT 1", "users");
if (database_num_rows ($query) != 1) { die("Invalid username or password. Please go back and try again."); }
$row = database_fetch_array ($query);
if (isset($_POST["rememberme"])) { $expiretime = time()+31536000; $rememberme = 1; } else { $expiretime = 0; $rememberme = 0; }
$cookie = $row["id"] . " " . $row["username"] . " " . md5($row["password"] . "--" . $dbsettings["secretword"]) . " " . $rememberme;
setcookie("dkgame", $cookie, $expiretime, "/", "", 0);
header("Location: index.php");
die();
}
$page = gettemplate("login");
$title = "Log In";
display ($page, $title, false, false, false, false);
}
function logout() {
setcookie("dkgame", "", time()-100000, "/", "", 0);
header("Location: login.php?do=login");
die();
}