nom du fichier: login.inc.php =
Code : Tout sélectionner
<?php
if (isset($_POST['formconnexion'])) {
require 'php/config2.inc.php';
$mail = $_POST['mailconnect'];
$password = $_POST['mdpconnect'];
if (empty($mail) || empty($password)) {
header("Location: connexion.php?error=emptyfields");
exit();
} else {
$sql = 'SELECT * FROM membres WHERE pseudo=?;';
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: connexion.php?error=sqlerror");
exit();
} else {
mysqli_stmt_bind_param($stmt, "s", $mail);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($row = mysqli_fetch_assoc($result)) {
$pwdcheck = password_verify($password, $row['motdepasse']);
if ($pwdcheck == false) {
header("Location: connexion.php?error=wrongpwd");
exit();
} else if($pwdcheck == true) {
session_start();
$_SESSION['UsersID'] = $row['id'];
$_SESSION['UsersUID'] = $row['pseudo'];
header("Location: espace.php?login=success");
exit();
} else {
header("Location: connexion.php?success=wrongpwd");
exit();
}
} else {
header("Location: connexion.php?error=nouser");
exit();
}
}
}
}
else {
header("Location: index.php");
exit();
}
?>Code : Tout sélectionner
<html>
<head>
<title>Connexion:</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style2.css">
<link rel="icon" type="image/png" href="https://i.dlpng.com/static/png/29205_preview.png" />
<link href="fontawesome/css/all.css" rel="stylesheet">
</head>
<body>
<?php include("includes/menu2.php"); ?>
<div align="center">
<form method="POST" action="login.inc.php" class="login" style="margin-right: 800px;" >
<h2 style="color: white;">Connexion</h2>
<input type="email" name="mailconnect" placeholder="Mail" />
<input type="password" name="mdpconnect" placeholder="Mot de passe" />
<br /><br />
<input type="submit" name="formconnexion" value="Se connecter !" />
</form>
</div>
</body>
</html>
Code : Tout sélectionner
<?php
$servername = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "systemlogin";
$conn = mysqli_connect($servername, $dbusername, $dbpassword, $dbname);
if(!$conn) {
die("Connection a échoué: ".mysli_connect_error());
}
?>