-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest2.php
More file actions
39 lines (32 loc) · 1.01 KB
/
Copy pathtest2.php
File metadata and controls
39 lines (32 loc) · 1.01 KB
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
<?php
// Connexion à la base
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
die("Erreur de connexion : " . $e->getMessage());
}
// Vérification login si formulaire soumis
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'];
$pass = $_POST['pass'];
// Requête pour vérifier si l'utilisateur existe
$sql = "SELECT * FROM users WHERE name = :name AND pass = :pass";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':pass', $pass);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
}
if ($result) {
// Connexion réussie → redirection vers une page HTML
header("Location: portfolio.html");
exit(); // toujours mettre exit() après header
} else {
echo "Nom ou mot de passe incorrect ❌";
}
?>