-
Notifications
You must be signed in to change notification settings - Fork 1
/
login.php
41 lines (38 loc) · 1.07 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
41
<?php
ob_start();
session_start();
include("./connect_to_db.php");
$db = DbUtil::loginConnection();
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$name = $_POST["username"];
$pword = md5($_POST["password"]);
$login = false;
$stmt = $db->stmt_init();
if ($stmt = $db->prepare("select username, password from Users where username = ? and password = ?")) {
$stmt->bind_param('ss', $name, $pword);
$stmt->execute();
$stmt->bind_result($name, $pass);
if ($stmt->fetch()) {
$_SESSION["login"] = true;
$_SESSION["username"] = $name;?>
<script type = "text/javascript">
document.cookie = "loginwrong=right";
window.location.replace("profile.php");
</script>
<?php
}
//Incorrect:
else{ ?>
<script type = "text/javascript">
document.cookie = "loginwrong=wrong";
window.location.replace("login.html");
</script>
<?php
}
}
$stmt->close();
$db->close();
?>