Advertisement
tonny16

Formulaire Connexion

Apr 26th, 2017
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.70 KB | None | 0 0
  1. <?php session_start(); ?>
  2. <!DOCTYPE html>
  3. <html>
  4.  
  5. <head>
  6.  
  7.     <meta charset="utf-8" />
  8.     <link rel="stylesheet" href="style.css" />
  9.  
  10.     <title>Connexion</title>
  11. </head>
  12.  
  13. <body>
  14.    
  15.     <!-- PHP -->
  16.     <?php
  17.    if(isset($_POST['connexion']))
  18.    {
  19.         if(empty($_POST['pseudo']))
  20.         {
  21.             $errors ['pseudo']  = "Veuillez remplir le champs pseudo ! ";    
  22.         }
  23.        if (empty($_POST['password']))
  24.        {
  25.            $errors ['password']  = "Veuillez indiquez votre mot de passe ! ";  
  26.        }
  27.         if(empty($errors))
  28.         {
  29.           try
  30.         {
  31.            $bdd = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', 'root');
  32.         }
  33.         catch (Exception $e)
  34.         {
  35.             die('Erreur : ' . $e->getMessage());
  36.         }
  37.  
  38.            
  39.           $reponse = $bdd->prepare("SELECT password FROM utilisateurs WHERE pseudo= :pseudo  ");
  40.           $reponse->execute(array('pseudo' => $_POST['pseudo']));
  41.           $donnees = $reponse->fetch();
  42.             if(empty($donnees)){
  43.             $problemes ['pseudo'] = "Le pseudo n'est pas bon ";
  44.               }
  45.            
  46.             if(password_verify($_POST['password'], $donnees['password']))
  47.             {
  48.                $_SESSION['pseudo'] = $_POST['pseudo'];
  49.                 echo 'Vous êtes connecté' ;
  50.             }
  51.             else
  52.             {
  53.                $problemes ['password'] = "Le mot de passe n'est pas correct";    
  54.             }
  55.             $reponse->closeCursor();
  56.         }
  57.        else
  58.         {
  59.            foreach($errors as $erreur)
  60.             {
  61.                $erreur;
  62.             }
  63.         }
  64.        if (isset($problemes)) {
  65.            foreach ($problemes as $probleme) {
  66.                $probleme;
  67.            }
  68.        }
  69.    }
  70.    
  71.    
  72.     ?>
  73.    
  74.    <?php
  75.    
  76.     if(empty ($errors))
  77.     {
  78.         $nomclass = "alert alert-dismissible alert-info";
  79.         $message = "Pas d'erreur";
  80.     }
  81.     else
  82.     {
  83.         $nomclass = "alert alert-dismissible alert-danger";
  84.         $message = $erreur;
  85.     }
  86.    
  87.    
  88.     ?>
  89.     <!-- Fin PHP  -->
  90.     <h1>Connexion</h1>
  91.  
  92.     <form method="post" class="form-horizontal">
  93.         <fieldset>
  94.  
  95.            
  96.             <div class="form-group">
  97.                 <label class="col-lg-2 control-label">Pseudo</label>
  98.                 <div class="col-lg-10">
  99.                     <input type="text" class="form-control" placeholder="Pseudo" name="pseudo" value="<?php if(isset($_POST['pseudo'])) { echo $_POST['pseudo'];} ?>" >
  100.                 </div>
  101.             </div>
  102.  
  103.            
  104.  
  105.             <div class="form-group">
  106.                 <label for="inputPassword" class="col-lg-2 control-label">Mot de passe</label>
  107.                 <div class="col-lg-10">
  108.                     <input type="password" class="form-control" id="inputPassword" name="password" placeholder="Mot de passe" data-cip-id="inputPassword">
  109.                 </div>
  110.             </div>
  111.  
  112.  
  113.             <div class="form-group">
  114.                 <div class="col-lg-10 col-lg-offset-2">
  115.                     <button type="submit" class="btn btn-primary" name="connexion">Connexion</button>
  116.                 </div>
  117.             </div>
  118.  
  119.         </fieldset>
  120.     </form>
  121.     <p> Vous pouvez vous déconnecter en cliquant <a href= 'deconnexion.php'><button type="submit" class="btn btn-primary" name="déconnexion">Déconnexion</button></a>
  122.    
  123.     <div class="<?php echo $nomclass ?>"> <?php echo $message ?> </div>
  124.  
  125.     <?php if(isset($_SESSION['pseudo'])){ ?>
  126.     <h1> Bienvenu dans votre espace personnel <?php if(isset($_POST[pseudo])) { echo htmlspecialchars($_POST['pseudo']) ; }?></h1>
  127.    
  128.        
  129.     <?php }
  130.    
  131.    
  132.    
  133.     ?>
  134. </body>
  135.  
  136. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement