Advertisement
Guest User

Untitled

a guest
Dec 26th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2.    
  3. $bdd = new PDO('mysql:host=127.0.0.1;dbname=siteweb', 'root', '');
  4.  
  5. if(isset($_POST) AND !empty($_POST)){
  6.  
  7.     if (!empty(htmlspecialchars($_POST['user'])) AND !empty(htmlspecialchars($_POST['mdp']))) {
  8.        
  9.         $req = $bdd->prepare('SELECT * FROM users WHERE pseudo = :user AND password = :mdp ');
  10.         $req->execute([
  11.             'user' => $_POST['user'],
  12.             'mdp' => $_POST['mdp']
  13.  
  14.         ]);
  15.         $user = $req->fetch();
  16.  
  17.         if($user){
  18.             session_start();
  19.             $_SESSION['admin'] = $_POST['user'];
  20.             header('location:index.php');
  21.  
  22.         } else {
  23.             $error = 'Identifiants incorrects !';
  24.         }
  25.  
  26.     } else {
  27.  
  28.             $error = 'Veuillez remplir tous les champs !';
  29.  
  30.     }
  31.  
  32. }
  33.  
  34. ?>
  35.  
  36.  
  37. <!DOCTYPE html>
  38. <html>
  39. <head>
  40.     <title>ToinePanel - Connection</title>
  41.     <link rel="stylesheet" type="text/css" href="css/main.css">
  42. </head>
  43. <body>
  44.  
  45.     <div class="form-">
  46.        
  47.         <h2>ToinePanel</h3>
  48.  
  49.         <p>Veuillez vous connectez:</p>
  50.  
  51.         <?php if(isset($error)){ echo "<div class='error'>" . $error . "</div> <br />";}  ?>
  52.  
  53.  
  54.         <form method="POST">
  55.            
  56.             <input type="text" name="user" required placeholder="Utilisateur" class="chp">
  57.             <input type="password" name="mdp" required placeholder="Mot de Passe" class="chp">
  58.  
  59.             <input type="submit" name="submit" value="Se connecter" class="submit">
  60.  
  61.         </form>
  62.  
  63.     </div>
  64.  
  65. </body>
  66. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement