Authentification avec session
Bonjour,
je conçois actu un espace de gestion mais déjà impossible d'accéder à la page dashboard.php car les identifiants de connexion entrés retourne un message d'erreur du genre "Vérifier vos identifiants de connexion" pourtant les identifiants entrés existent bien et son présent dans la base de données. Le problème est peut être au niveau de mon script alors je m'en remet à vos conseils avisés.
CODE:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
<?php
session_start();
//J'ouvre ma base de donnée
$dbname= 'mabase';
$user = 'root';
$password = '';
$host = 'localhost';
try {
$bdd = new PDO('mysql:host='.$host .';dbname='.$dbname, $user, $password );
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$bdd->exec("SET CHARACTER SET utf8");
} catch (PDOException $e) {
echo "<p>Erreur : " . $e->getMessage() . "</p>";
exit();
}
if(isset($_POST['submit'])){
$errMsg = '';
//login and password sent from Form
$login = trim($_POST['login']);
$pass = trim($_POST['pass']);
if($login == '')
$errMsg .= 'Veuillez entrer votre nom<br>';
if($pass == '')
$errMsg .= 'Veuillez entrer votre mot de passe<br>';
if($errMsg == ''){
$records = $bdd->prepare('SELECT id,login,pass FROM user WHERE login = :login');
$records->bindParam(':login', $login);
$records->execute();
$results = $records->fetch(PDO::FETCH_ASSOC);
if(count($results) > 0 && password_verify($pass, $results['pass'])){
$_SESSION['login'] = $results['login'];
header('location:dashboard.php');
exit;
}else{
$errMsg .= 'Vérifiez vos identifiants de connexion<br>';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ADMIN | Accès</title>
<style type="text/css">
body
{
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
background-image: url(../Images/nice.jpg);
background-attachment: fixed;
background-repeat: no-repeat;
margin-top: 50px;
}
label
{
font-weight:bold;
width:100px;
font-size:14px;
color: #FFFFFF;
}
.box
{
border:1px solid #006D9C;
margin-left:10px;
width:60%;
}
.submit{
border:1px solid #f50c49;
background-color:#f50c49;
color:#FFFFFF;
float:right;
padding:2px;
margin-right: 15px;
}
.tLink{
font-size: 72px;
color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>
<div align="center">
<br />
<div class="tLink"><strong>ADMINISTRATION</strong></div><br />
<div style="width:300px; border: solid 1px #f50c49; " align="left">
<?php
if(isset($errMsg)){
echo '<div style="color:#FF0000;text-align:center;font-size:12px;">'.$errMsg.'</div>';
}
?>
<div style="background-color:#f50c49; color:#FFFFFF; padding:3px;"><b>Authentification</b></div>
<div style="margin:30px">
<form action="" method="post">
<label>Username:</label><input type="text" name="login" class="box"/><br /><br />
<label>Password:</label><input type="password" name="pass" class="box" /><br/><br />
<input type="submit" name='submit' value="Se connecter" class='submit'/><br />
</form>
</div>
</div>
</div>
</body>
</html> |