Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'inc/function.php';
- session_start();
- if(!empty($_POST)){
- $errors = array();
- require_once 'inc/db.php';
- //$pdo = new PDO('mysql:host=localhost;dbname=ProjetWeb;charset=utf8', 'root', 'root');
- if(empty($_POST['username']) || !preg_match('/^[a-zA-Z0-9_]+$/',$_POST['username'])){
- $errors['username'] = "vous n'avez pas rentré de pseudo";
- } else{
- $req = $pdo->prepare('SELECT id FROM membres WHERE username = ?');
- $req->execute([$_POST['username']]);
- $user = $req->fetch();
- if($user){
- $errors['username'] = 'ce pseudo est déjà pris';
- }
- }
- if(empty($_POST['email'])){
- $errors['email'] = "email invalide";
- } else{
- $req = $pdo->prepare('SELECT id FROM membres WHERE email = ?');
- $req->execute([$_POST['email']]);
- $email = $req->fetch();
- if($email){
- $errors['email'] = 'cet email est déjà pris';
- }
- }
- if(empty($_POST['password']) || $_POST['password'] != $_POST['password-confirm'] ){
- $errors['password'] = "Veuillez rentrer le même mot de passe";
- }
- if(empty($errors)) {
- $req = $pdo->prepare("INSERT INTO membres SET username = ?, password = ?,email = ?,confirmation_token = ?");
- $password = password_hash($_POST['password'], PASSWORD_BCRYPT);
- $token = str_random(60);
- $req->execute(array($_POST['username'], $password, $_POST['email'],$token));
- $user_id = $pdo->lastInsertId();
- mail($_POST['email'],'Confirmation de votre compte ',"Afin de valider votre compte merci de cliquer csur ce lien\n\nhttp://localhost/confirm.php?id=$user_id&token=$token");
- echo 'http://localhost/confirm.php?id=$user_id&token=$token';
- $_SESSION['flash']['success'] = 'un email de confirmation vous a été envoyé';
- header('Location: login.php');
- exit();
- }
- }
- ?>
- <?php require 'inc/header.php'; ?>
- <h1>S'inscrire</h1>
- <?php if (!empty($errors)): ?>
- <div class="alert alert danger">
- <p>Vous n'avez pas rempli le formulaire correctement</p>
- <ul>
- <?php foreach ($errors as $error): ?>
- <li><?= $error; ?></li>
- <?php endforeach; ?>
- </ul>
- </div>
- <?php endif; ?>
- <form action="" method="POST">
- <div class="form-group"></div>
- <label for="">Pseudo</label>
- <input type="text" name="username" class= "form-control"/>
- <div class="form-group"></div>
- <label for="">Email</label>
- <input type="email" name="email" class="form-control"/>
- <div class="form-group"></div>
- <label for="">Mot de passe</label>
- <input type="password" name="password" class="form-control"/>
- <div class="form-group"></div>
- <label for="">Confirmer Mot de passe</label>
- <input type="password" name="password-confirm" class="form-control"/>
- <button type="submit" class="btn btn-primary">S'enregistrer</button>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement