Show sourcecode
The following files exists in this folder. Click to view.
adminlogin.php
createtables.php
createtest.php
dbconnection.php
index.php
kundsida.php
result.php
test.php
index.php
99 lines UTF-8 Windows (CRLF)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
ini_set('output_buffering', 0); // Do not buffer outputs, write directly
include('dbconnection.php');
date_default_timezone_set("Europe/Stockholm")
?>
<?php
session_start();
$warningMsg = "";
if (isset($_POST["login"])) {
try {
$sql = "SELECT id, username, password FROM users";
$stmt = $dbconn->prepare($sql);
$data = array();
$stmt->execute($data);
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($_POST["user"] === $res['username'] && $_POST["password"] === $res['password']) {
$_POST["user"] === $_SESSION['username'];
$_SESSION["logIn"] = true;
$_SESSION["AlogIn"] = false;
$_SESSION["userid"] = $res["id"];
$sql = "UPDATE users SET login_date=?
WHERE username=?";
$stmt = $dbconn->prepare($sql);
$data = array(date("Y-m-d H:i:s"), $_POST["user"]);
$stmt->execute($data);
header("Location: kundsida.php");
} else
echo "Fel uppgifter!<br>";
}
}
catch(PDOException $e)
{
echo $sql . "<br />" . $e->getMessage();
}
}
if (isset($_POST["create"])) {
try {
$sql = "INSERT INTO users (name, username, password, login_date)
VALUES (?, ?, ?, now())";
$stmt = $dbconn->prepare($sql);
$data = array($_POST["name"], $_POST["user"], $_POST["password"]);
$stmt->execute($data);
$_SESSION["logIn"] = true;
header("Location: kundsida.php");
}
catch(PDOException $e)
{
echo $sql . "<br />" . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<nav>
<a href="index.php">Login</a> <br>
<a href="result.php">Resultat</a> <br>
<a href="kundsida.php">Kundsida</a> <br>
<a href="adminlogin.php">Admin</a>
</nav>
<div style="display: flex; justify-content:space-around; margin: auto">
<div>
<h1>Logga in</h1>
<form method="post" action="">
<br>
<input type="text" name="user" placeholder="Användarnamn" required><br>
<br>
<input type="password" name="password" placeholder="Lösenord" required><br>
<br>
<input type="submit" name="login">
</form>
</div>
<div>
<h1>Skapa konto</h1>
<form method="post" action="">
<br>
<input type="text" name="name" placeholder="Namn" required><br>
<br>
<input type="text" name="user" placeholder="Användarnamn" required><br>
<br>
<input type="password" name="password" placeholder="Lösenord" required><br>
<br>
<input type="submit" name="create">
</form>
</div>
</div>
</body>
</html>