problème avec ma page login.php
Posté : 28 août 2018, 01:58
Bonsoir je viens à vous pour pouvoir terminer ma page membre de mon site.
Mon problème ,ma page de connexion (sign_up.php) marche bien , j'arrive à inscrire un utilisateur.Mais ma page de connexion (login.php) ne marche pas ,elle n'affiche rien,quand je me connecte.
J'utilise WampServer V2.5
sign_up.php
Mon problème ,ma page de connexion (sign_up.php) marche bien , j'arrive à inscrire un utilisateur.Mais ma page de connexion (login.php) ne marche pas ,elle n'affiche rien,quand je me connecte.
J'utilise WampServer V2.5
sign_up.php
<?php
session_start();
include('config.php');
?>
<!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=utf-8" />
<link rel="stylesheet" href="img.css"/>
<title>Espace membre</title>
</head>
<body>
<div class="header">
<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/img/logo.png" alt="Espace Membre" /></a>
</div>
<div class="content">
<?php
if (isset($_SESSION['id']) AND isset($_SESSION['pseudo']))
{
echo 'Bonjour ' . $_SESSION['pseudo'];
}
?>
<?php
require_once 'function.php';
if(!empty($_POST)){
$errors = array();
require_once 'config.php';
if(empty($_POST['username'])){
$errors['username'] = "Votre pseudo est vide";
}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éja utilsé";
}
}
if(empty($_POST['email']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)){
$errors['email'] = "Votre email n'est pas valide";
}else{
$req = $pdo->prepare("SELECT id FROM membres WHERE email = ?");
$req->execute([$_POST['email']]);
$user = $req->fetch();
if($user){
$errors['email'] = "Cet email est déja utilsé";
}
}
if(empty($_POST['password']) || $_POST['password'] != $_POST['password_confirm']){
$errors['password'] = "Vous devez rentrer un mot de passe valide";
}
if(empty($errors)){
$req = $pdo->prepare("INSERT INTO membres SET username=?,password=?,email=?");
$password = md5($_POST['password']);
$req->execute([$_POST['username'],$password,$_POST['email']]);
exit();
}
}
?>
<h1>S'inscrire</h1>
<form action="sign_up.php" method = "POST">
<div class="form-group">
<label for="">Pseudo</label>
<input type ="text" name="username" placeholder="Franc18" class="form-control" />
</div>
<div class="form-group">
<label for="">Adresse email</label>
<input type ="text" name="email" placeholder="[email protected]" class="form-control" />
</div>
<div class="form-group">
<label for="">Mot de passe</label>
<input type ="password" name="password" placeholder="xjvfgh134" class="form-control" />
</div>
<div class="form-group">
<label for="">Confirmer mot de passe</label>
<input type ="password" name="password_confirm" placeholder="xjvfgh134" class="form-control" />
</div>
<button type="submit" class="btn-btn-primary">M'inscrire</button>
</form>
<div class="foot"><a href="index.php">Retour à l'accueil</a> - <a href="#">Support du Web</a></div>
</body>
</html>
Ensuite login.php
<?php
include('config.php');
?>
<!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=utf-8" />
<link rel="stylesheet" href="img.css"/>
<title>Espace membre</title>
</head>
<body>
<div class="header">
<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/img/logo.png" alt="Espace Membre" /></a>
</div>
<?php
// Vérification des identifiants
if(!empty($_POST) && !empty($_POST['username']) && !empty($_POST['password'])){
$req = $pdo->prepare('SELECT * FROM membres WHERE username = :username OR email = :username');
$req->execute(['username'=>$_POST['username']]);
$user = $req->fetch();
if(password_verify($_POST['password'],$user->password)){
$_SESSION['auth'] = $user;
header('Location:index.php');
exit();
}
}
?>
<div class="content">
<form action="login.php" method="post">
Veuillez entrer vos identifiants pour vous connecter:<br />
<div class="center">
<label for="username">Nom d'utilisateur</label><input type="text" name="username" id="username" value="" /><br />
<label for="password">Mot de passe</label><input type="password" name="password" id="password" /><br />
<input type="submit" value="Se connecter" />
</div>
</form>
</div>
<?php ?>
<div class="foot"><a href="sign_up.php">Retour à l'accueil</a> - <a href="http://www.supportduweb.com/">Support du Web</a></div>
</body>
</html>