-
Notifications
You must be signed in to change notification settings - Fork 3
/
login_example.php
63 lines (61 loc) · 1.53 KB
/
login_example.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
<body>
<h1>Login Demo</h1>
<div>
<?php
session_start();
$showFormular = false;
echo $_SESSION['userid'];
if (!isset($_SESSION['userid'])) {
$showFormular = true;
//echo "Session-ID not set!<br>";
if(isset($_GET['login'])) {
$name = $_POST['name'];
$password = $_POST['password'];
if ($name == 'user' && $password == 'password') {
$_SESSION['userid'] = $name;
echo 'Login successful.<br><br>';
header("Refresh:0; url=".$pagename."?login=1");
$showFormular = false;
} else {
echo'Username oder Passwort ungültig.<br><br>';
if(isset($_POST['name']))header("Refresh:0; url=".$pagename."?login=2");
$showFormular = true;
}
}
}
if($showFormular) {
?>
<h2>Login</h2>
<form action="?login=1" method="post">
Name:<br>
<input size="40" maxlength="250" name="name"><br><br>
Password:<br>
<input type="password" size="40" maxlength="250" name="password"><br><br>
<input type="submit" value="Abschicken">
</form>
<?php
}
?>
<?php
if(isset($_SESSION['userid']) && isset($_GET['logout'])) {
session_start();
session_destroy();
header("Refresh:0; url=".$pagename);
}
if(isset($_SESSION['userid'])){
echo "<h1>Private Section</h1>";
echo "<h2>Login successful</h2>";
echo "<p>Private content.</p>";
?>
<form action="?logout=0" method="POST">
<input type="submit" name="logout" class="button" value="Logout" />
</form>
<br><br>
<?php
}
?>
</div>
</body>
</html>