-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
53 lines (49 loc) · 1.54 KB
/
index.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
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Connexion</title>
</head>
<body>
<pre>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<label for="username">Nom d'utilisateur</label>
<input type="text" name="username" id="username">
<label for="password">Mot de passe</label>
<input type="password" name="password" id="password"><br>
<input type="submit" value="Se connecter">
</form>
</pre>
</body>
</html>
<?php
if ($_SERVER['REQUEST_METHOD'] === "POST") {
if(isset($_POST['username']) && isset($_POST['password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if ($username === 'admin' AND $password === 'admin') {
//Initialisation de notre session en tant qu'administrateur
$_SESSION['admin'] = true;
$_SESSION['username'] = $username;
//Creation du cookie admin
setcookie('user', 'admin', time() + 3600, '/');
//redirection
header("location:home.php");
// echo "Bienvenue à toi, $username";
}
if ($username === 'user' AND $password === 'user') {
//Initialisation de notre session en tant qu'administrateur
$_SESSION['admin'] = false;
$_SESSION['username'] = $username;
//Creation du cookie admin
setcookie('user', 'user', time() + 3600, '/');
//redirection
header("location:home.php");
// echo "Bienvenue toi, $username";
}
}}
?>