bonsoir j'ai un problème dû à la récupération d'une vérification via la session.
Voici mon code de traitement login :
<?php
require '../includes.php';
$errors = [];
$success = [];
$identifiant = $_POST['identifiant'];
$password = sha1($_POST['password']);
// Gestion des success
$success['inscription'] = "Vous vous êtes bien inscrit !";
// Gestion des errors
if(!array_key_exists('identifiant', $_POST) || $identifiant == '')
{
$errors['identifiant'] = "Vous n'avez pas renseigné votre identifiant !";
}
if(!array_key_exists('password', $_POST) || $password == '')
{
$errors['password'] = "Vous n'avez pas renseigné votre mot de passe !";
}
// Traitement du formulaire
if(!$errors)
{
$req = $db->prepare("SELECT * FROM users WHERE identifiant = :identifiant AND password = :password");
$req->bindParam(":identifiant", $identifiant);
$req->bindParam(":password", $password);
$req->execute();
$data = $req->rowCount();
if($data)
{
$_SESSION['Auth'] = $req->fetch();
$_SESSION['success'] = $success;
header('Location: '. WEBROOT .'index.php');
}
}else{
$_SESSION['errors'] = $errors;
header('Location: '. WEBROOT .'index.php');
}
?>
Et voici l'index :
<?php
require 'app/includes.php';
require 'app/classes/form.php';
$title = "Système de membres";
require 'partials/header.php';
?>
<?php if(!isset($_SESSION['Auth'])): ?>
<div class="page-header">
<h3>
<i class="fa fa-lock"></i>
Connexion à mon compte
</h3>
</div>
<?php if(array_key_exists('errors', $_SESSION)): ?>
<div class="alert alert-danger">
<?= "<li>".implode("</li><li>", $_SESSION['errors'])."</li>"; ?>
</div>
<?php
unset($_SESSION['errors']);
endif;
?>
<?php if(array_key_exists('success', $_SESSION)): ?>
<div class="alert alert-success">
<?= "<p>".implode("</p><p>", $_SESSION['success'])."</p>"; ?>
</div>
<?php
unset($_SESSION['success']);
endif;
?>
<?= Formulaire::start("post", "app/models/login.php"); ?>
<?= Formulaire::input("text", "identifiant", "user", "Votre identifiant"); ?>
<?= Formulaire::input("password", "password", "key", "Votre mot de passe"); ?>
<?= Formulaire::btn("submit", "default", "lock", "S'authentifier"); ?>
<a href="inscription.php" class="btn btn-success btn-lg btn-block">
<i class='fa fa-user-plus'></i>
Je ne suis pas encore inscrit !
</a>
<?= Formulaire::end(); ?>
<?php endif; ?>
<?php if(isset($_SESSION['Auth'])): ?>
<?php endif; ?>
<?php
require 'app/debug.php';
require 'partials/footer.php';
?>
Quand je ne rentre aucune informations dans le formulaire, le traitement ne me renvoie que l'erreur "Vous n'avez pas renseigné votre identifiant" et ne me renvoie pas l'erreur du password vide !