-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.php
More file actions
38 lines (32 loc) · 1.17 KB
/
signup.php
File metadata and controls
38 lines (32 loc) · 1.17 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
<?php
require 'config.php';
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Basic validation instead of sanitization
$email = trim($_POST['email']);
$password = password_hash(trim($_POST['password']), PASSWORD_DEFAULT);
// Vérifier si l'email existe déjà
$stmt = $conn->prepare("SELECT id FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$_SESSION['error'] = "Email déjà utilisé.";
header("Location: creation_compte.php");
exit;
}
$stmt = $conn->prepare("INSERT INTO users (email, password) VALUES (?, ?)");
$stmt->bind_param("ss", $email, $password);
if ($stmt->execute()) {
$_SESSION['user_email'] = $email;
unset($_SESSION['error']); // Effacer l'erreur si l'inscription réussit
header("Location: creation_profil.php");
} else {
$_SESSION['error'] = "Erreur lors de la création du compte.";
header("Location: creation_compte.php");
}
$stmt->close();
}
?>