PHP

Système de connexion

Non Résolu

Bonjour à tous,

J'ai créé mon système de connexion sans souci cependant lorsqu'un utilisateur s'inscrit sur mon site il doit se faire valider par l'administrateur avant de pouvoir se connecter au site du coup j'ai créé une propriété "état" qui prend la valeur "accepté" lorsque l'inscription de l'utilisateur est belle et bien accepté mais lorsque j'ajoute cette condition au système de connexion initial je ne peut pas me connecter

session_start(); // début de session
$pdo= new PDO("mysql:host=localhost;dbname=alumnicampc","root","");
if ($_SERVER["REQUEST_METHOD"] == "POST"){ // execution apres envoi du formulaire
   if(!empty($_POST["identifiantConnexion"]) AND !empty($_POST['motDePasse'])){
    @$identifiantConnexion = htmlspecialchars($_POST['identifiantConnexion']);
    @$motDePasse = $_POST['motDePasse'];
    $errors = [];
    $etat = "";
 
 
    $recupUser = $pdo -> prepare("SELECT * FROM utilisateurs WHERE identifiantConnexion = ? AND motDePasse = ? AND etat = 'accepté'");
    @$recupUser-> execute(array($identifiantConnexion,$motDePasse,$etat));
   
    if($recupUser -> rowCount() > 0){
       
    $_SESSION['identifiantConnexion'] = $identifiantConnexion;
    $_SESSION['motDePasse'] = $motDePasse;
    $_SESSION['id'] = $recupUser->fetch()['id'];
    $_SESSION['nom'] = $recupUser->fetch()['id']['nom'];
    header('Location: Accueil.php');
   }else{
    $errors['Erreur1']="Identifiant ou mot de passe incorrect !";
   }
 }else{
    $errors['Erreur2']="Veuillez remplir tout les champs !";
 }
   
}
423 vues
30 décembre 2022 à 9:12
Cette pub permet au site de vivre ...

3 commentaires

Bonjour, tu as compliqué ton système de connexion pour rien.

Voici la modification de ton code pour qu'il marche mieux

session_start(); // début de session
$pdo= new PDO("mysql:host=localhost;dbname=alumnicampc","root","");
 if(isset($_POST["identifiantConnexion"]) && isset($_POST['motDePasse'])){
    $identifiantConnexion = htmlspecialchars($_POST['identifiantConnexion']);
    $motDePasse = htmlspecialchars($_POST['motDePasse']);
    $errors = [];
    $etat = "accepté";

    if(!empty($identifiantConnexion) && !empty($motDePasse)):
 
      $recupUser = $pdo ->prepare("SELECT * FROM utilisateurs WHERE identifiantConnexion = ? AND motDePasse = ? AND etat = ?");
      $recupUser->execute(array($identifiantConnexion,$motDePasse,$etat));
      $data_fetch = $recupUser->fetchAll();
   
      if($data_fetch){
         
         $_SESSION['data_user'] = $data_fetch;
         header('Location: Accueil.php');
      } else {
         $errors['Erreur1'] = "Identifiant ou mot de passe incorrect !";
      } else {
        $errors['Erreur2'] = "Veuillez remplir tout les champs !";
   }}
     

Bonsoir @yann333,


Ton problème a-t-il pu se résoudre ? 🤔

Bonsoir @yann333 !


Voici la modification :

$recupUser = $pdo->prepare("SELECT * FROM utilisateurs WHERE identifiantConnexion = ? AND motDePasse = ? AND etat = ?");
$recupUser->execute(array($identifiantConnexion,$motDePasse,"accepté"));


Bonne soirée !

Cette pub permet au site de vivre ...