authentification (pro code)
This commit is contained in:
parent
ce06182532
commit
9f11673c3a
41
admin123/admin.php
Normal file
41
admin123/admin.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
session_start();
|
||||
|
||||
if(isset($_POST["disconect"])) {
|
||||
$_SESSION = array();
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
if (isset($_SESSION['user'], $_SESSION['password'])) {
|
||||
|
||||
$prout = $_SESSION['user'];
|
||||
|
||||
} else {
|
||||
header('Location: index.php');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
<title>
|
||||
Mon super portfolio
|
||||
</title>
|
||||
</head>
|
||||
<body style="font-family: Arial, sans-serif;">
|
||||
<h1>Administration</h1>
|
||||
<p>Bonjour <span style="font-weight: bold"><?php echo $prout ?></span></p>
|
||||
|
||||
|
||||
<form action="" method="POST">
|
||||
<input type="hidden" name="disconect" value="disconect"/>
|
||||
<input type="submit" value="CIAO"/>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
48
admin123/index.php
Normal file
48
admin123/index.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
require '../lib/database.php';
|
||||
require '../lib/login.php';
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
if (isset($_POST['user'], $_POST['password'])) {
|
||||
$user = trim($_POST['user']);
|
||||
$password = trim($_POST['password']);
|
||||
|
||||
$valid = true;
|
||||
|
||||
foreach ([$user, $password] as $field) {
|
||||
if (empty($field)) {
|
||||
$valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($valid) {
|
||||
login($user, $password);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
<title>
|
||||
Mon super portfolio
|
||||
</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ici, c'est l'administration, c'est ici qu'on trouve toute l'administration.</h1>
|
||||
|
||||
<form action="" method="POST">
|
||||
<label for="user">User :</label>
|
||||
<input type="text" id="user" name="user"/>
|
||||
<label for="password">password :</label>
|
||||
<input type="password" id="password" name="password"/>
|
||||
|
||||
<input type="submit" value="go go go"/>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
33
lib/login.php
Normal file
33
lib/login.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Enregistre un nouveau commentaire
|
||||
*
|
||||
* @param string $user nom de l'utilisateur
|
||||
* @param string $password user's password
|
||||
*/
|
||||
function login($user, $password)
|
||||
{
|
||||
$pdo = getDatabaseConnection();
|
||||
|
||||
$query = $pdo->prepare('SELECT * FROM user');
|
||||
|
||||
$query->execute();
|
||||
|
||||
$userList = $query->fetchAll();
|
||||
|
||||
foreach ($userList as $k) {
|
||||
if ($k['user'] == $user && $k['password'] == $password) {
|
||||
|
||||
session_start();
|
||||
|
||||
$_SESSION['user'] = $user;
|
||||
$_SESSION['password'] = $password;
|
||||
|
||||
header('Location: admin.php');
|
||||
|
||||
} else {
|
||||
header('Location: index.php');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -142,6 +142,7 @@ function createComment($name, $email, $website, $content, DateTime $date, $proje
|
|||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Génère et retourne une pagination
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue