-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
66 lines (52 loc) · 2.44 KB
/
index.php
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
<?php
include_once ('initialization.php');
?>
<html lang="fr">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP Exam</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<link href='https://fonts.googleapis.com/css?family=Roboto:400,700,300' rel='stylesheet' type='text/css'>
</head>
<body>
<a href="admin.php" class="uppercase admin-button">Admin</a>
<?php
if(count($_POST) > 0) {
// 1.Honeypot
if($_POST['name'] != ''){
die('Spammeur !');
}
// 2.Nettoyage
$email = trim(strip_tags($_POST['email']));
// 3.Validation
$errors = array();
if(!is_valid_email($email)) {
$errors['email'] = 'Vous devez entrer une adresse email valide.';
} else if(emailExists($connexion, $email)){
$errors['email'] = 'Cette adresse email est déjà dans notre base de données.';
}
if(count($errors) < 1){
$uniqid = uniqid();
include 'mail.inc.php';
$sql = 'INSERT INTO users(user_id, email, date, state) VALUES(:user_id, :email, now(), :state)';
$preparedStatement = $connexion->prepare($sql);
$preparedStatement->bindValue('user_id', $uniqid);
$preparedStatement->bindValue('email', $email);
$preparedStatement->bindValue('state', 'off');
$preparedStatement->execute();
}
}
?>
<form class="inscription-form" method="post">
<label class="name" for="name">Name</label>
<input class="name" type="text" id="name" name="name">
<div>
<label for="email">Inscription à la newsletter</label>
<input type="text" id="email" name="email" placeholder="exemple@mail.com">
<?php echo message_erreur($errors, 'email'); ?>
</div>
<input type="submit" name="inscription" value="Inscription">
</form>
</body>
</html>