Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- require_once('bdd_connexion.php');
- if(empty($_SESSION['id'])){
- if(isset($_POST['formconnexion'])){
- $emailconnect = htmlspecialchars($_POST['emailconnect']);
- $passwordconnect = $_POST['passwordconnect'];
- if(!empty($emailconnect) AND !empty($passwordconnect)){
- $q = $db->prepare('SELECT * FROM users WHERE email = ?'); // Préparation de la requete SQL
- $q->execute([$emailconnect]); // Execution de la requete
- $user = $q->fetch(PDO::FETCH_OBJ); // Va chercher l'id de l'utilisateur
- if($user && password_verify($passwordconnect, $user->password)) {
- // Création des sessions
- $_SESSION['id'] = $user->id;
- $_SESSION['username'] = $user->username;
- $_SESSION['email'] = $user->email;
- // redirection vers le compte utilisateur
- header("Location: index.php");
- }else{
- $alert = "Mauvais mail ou mot de passe";
- }
- }else{
- $alert = "Vous devez compléter tous les champs";
- }
- }
- }else{
- if(isset($_GET['logout'])){
- session_destroy();
- header("Location: index.php");
- }
- }
- ?>
- <!DOCTYPE html>
- <html lang="fr-FR">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <title>Mon compte</title>
- <!--[if lt IE 9]>
- <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- </head>
- <body>
- <center>
- <b style="color: red;">
- <?php if(isset($alert)){echo($alert.'<br>');} ?>
- </b>
- </center>
- <?php if(empty($_SESSION['id'])): ?>
- <form method="POST">
- <center>
- <label>Adresse email :</label>
- <input type="email" name="emailconnect"><br><br>
- <label>Mot de passe :</label>
- <input type="password" name="passwordconnect"><br><br>
- <button type="submit" name="formconnexion">Valider</button>
- </center>
- </form>
- <?php else: ?>
- <a href="index.php?logout">Se déconnecter</a><br><br>
- <b><?= $_SESSION['id'] ?></b><br>
- <b><?= $_SESSION['username'] ?></b><br>
- <b><?= $_SESSION['email'] ?></b><br>
- <?php endif; ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement