-
Notifications
You must be signed in to change notification settings - Fork 1
/
userauth.php
49 lines (40 loc) · 1004 Bytes
/
userauth.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
41
42
43
44
45
46
47
48
49
<?php
include_once("classes.php");
session_start();
function login($user, $pxwd, $db){
$newUser = new User($user, $pxwd, $db);
if ($newUser->isLoggedIn()){
// If authentication successful, start user session...
$_SESSION["user"] = $newUser;
}
else{
// If authentication failed, destroy new user container...
unset($newUser);
// And redirect to login page
header("Location: index.php?err=1");
}
}
function logout(){
unset($_SESSION["user"]);
$_SESSION["user"] == NULL;
session_destroy();
}
//=============================================================
if (isset($_POST["type"])){
if ($_POST["type"] == "logout"){
logout();
header("Location: index.php");
}
elseif ($_POST["type"] == "login"){
// Hash the password
// $pxwd = crypt($_POST["pxwd"]);
$pxwd = $_POST["pxwd"];
// Start database connection
$db = new Database();
// Session admittance
login($_POST["user"], $pxwd, $db);
// And redirect to main page
header("Location: players.php");
}
}
?>