-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInlogg.php
More file actions
74 lines (64 loc) · 1.94 KB
/
Inlogg.php
File metadata and controls
74 lines (64 loc) · 1.94 KB
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
<?php
session_start()
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
</head>
<body>
<?php
/*--------------------------*\
| Koden för inloggningen |
\*--------------------------*/
?>
<form action = "Inlogg.php" method = "POST">
<p> Login </p>
Name
<input type="text" name="Username" value=""> <br>
Password
<input type="password" name="Password" value=""> <br>
<br>
<input type="submit" name="submit" value="Login">
</form>
<?php
if(!empty($_POST["Username"]) && !empty($_POST["Password"])){
try {
$pdo = new PDO("mysql:dbname=TomteVerkstad;host=localhost", $_POST["Username"], $_POST["Password"]); // koden för att ansluta till databasen
$_SESSION["Username"] = $_POST["Username"];
$_SESSION["Password"] = $_POST["Password"];
echo "Login successfull";
echo "<br>";
}
catch (PDOException $e) {
exit("Login failed: " . $e->getMessage());
}
}
echo "<br>";
/*--------------------------*\
| Koden för utloggningen |
\*--------------------------*/
?>
<form action = "Inlogg.php" method = "POST">
<input type="hidden" name="Logout" value="True">
<input type="submit" name="submit" value="Logout">
</form>
<?php
if(!empty($_POST["Logout"])){
$_SESSION["Username"] = "";
$_SESSION["Password"] = "";
echo "Logout successfull";
echo "<br>";
}
echo "<br>";
/*----------------------------*\
| Koden för att flyta sida |
\*----------------------------*/
?>
<form action = "TomteVerkstad.php" method = "POST">
<input type="submit" name="submit" value="Move">
</form>
</body>
</html>