Guest User

register.php

a guest
Jul 24th, 2018
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. <?php
  2. include('includes/header.php');
  3. require'includes/em/function.php';
  4.  
  5. if(!empty($_POST)){
  6. require_once ('includes/em/config.php');
  7.  
  8. $errors = array();
  9.  
  10. if(empty($_POST ['username'] ) || !preg_match('/^[A-Z0-9]{4,64}$/i', $_POST ['username'])){
  11. $errors['username'] = "Votre pseudo doit contenir uniquement des caractères alphanumériques";
  12.  
  13. } else {
  14.  
  15.  
  16. $req = $pdo->prepare('SELECT id FROM users WHERE username = ?');
  17. $req->execute([$_POST]['username']);
  18. $user = $req->fetch();
  19. if($user){
  20.  
  21. $errors['username'] = 'Ce pseudo est déjà utilisé !';
  22.  
  23. }
  24.  
  25.  
  26.  
  27. if(empty($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
  28. $errors['email'] = "Votre email n'est pas valide";
  29.  
  30. }
  31. } else {
  32.  
  33.  
  34. $req = $pdo->prepare('SELECT id FROM users WHERE email = ?');
  35. $req->execute([$_POST]['email']));
  36. $user = $req->fetch();
  37. if($user){
  38.  
  39. $errors['email'] = 'Cette adresse email est déjà utilisé !';
  40.  
  41. }
  42. }
  43.  
  44.  
  45.  
  46. }
  47.  
  48.  
  49. if(empty($_POST['password']) ){
  50. $errors['password'] = "Votre mot de passe n'est pas valide";
  51.  
  52.  
  53. }
  54. }
  55.  
  56. if(empty($errors)){
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. $req = $pdo->prepare("INSERT INTO users SET username = ? , email = ? , password = ?");
  64. $password = password_hash($_POST ['password'], PASSWORD_BCRYPT);
  65. $req->execute(array($_POST['username'], $_POST['email'], $password));
  66. die("Votre compte à été crée allez dans la rubrique <a href=\"login.php\">Connexion");
  67.  
  68.  
  69.  
  70. }
  71.  
  72. debug($errors);
  73.  
  74. }
  75.  
  76. }
  77.  
  78. //minute de vidéo 22:39
  79.  
  80.  
  81. ?>
  82.  
  83. <!doctype html>
  84. <html lang="fr">
  85. <head>
  86. <!-- Required meta tags -->
  87. <meta charset="utf-8">
  88. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  89.  
  90. <!-- Bootstrap CSS -->
  91.  
  92. <link rel ="stylesheet" href ="css/style.css">
  93. <link rel ="stylesheet" href ="bootstrap/bootstrap.min.css">
  94. <link rel="icon" type="image/png" href="img/favicon.png">
  95. <title>MrLiamsi | Inscription </title>
  96. <style> .form-group {width:500px;} </style>
  97. </head>
  98. <body>
  99.  
  100.  
  101. <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  102. <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  103. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
  104.  
  105.  
  106.  
  107. <br>
  108. <br>
  109. <br>
  110.  
  111.  
  112. <form method="POST">
  113. <div align = "center">
  114. <hr/>
  115. <div class="form-group">
  116.  
  117. <label for="username" class="control-label">Pseudo : </label>
  118. <input type="text" name="username" id = "formsend"class="form-control">
  119.  
  120. </div>
  121. <div class="form-group">
  122. <label for="email" class="control-label">Adresse Mail : </label>
  123. <input type="email" name="email" id = "formsend"class="form-control">
  124.  
  125. </div>
  126.  
  127. <div class="form-group">
  128. <label for="password" class="control-label">Mot de passe : </label>
  129. <input type="password" name="password" id = "formsend"class="form-control" autocomplete="off">
  130.  
  131. </div>
  132. <div class="form-group">
  133. <label for="password" class="control-label">Confirmez votre mot de passe : </label>
  134. <input type="password" name="password_confirm" id = "formsend"class="form-control" autocomplete="off">
  135.  
  136. </div>
  137.  
  138. <div class="form-group">
  139. <input type="submit" name="btn-register" value="S'inscrire" class="btn btn-secondary">
  140. </div>
  141. <br/>
  142. <a href="login.php">Connexion</a>
  143. <hr/>
  144. </div>
  145. </form>
  146.  
  147.  
  148.  
  149.  
  150. <?php
  151.  
  152. require('includes/footer.php');
  153. ?>
  154.  
  155.  
  156.  
  157. </body>
  158. </html>
Add Comment
Please, Sign In to add comment