2024-09-11 13:06:40 +00:00
|
|
|
<?php
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
// Générer ou récupérer le token CSRF
|
|
|
|
if (empty($_SESSION['csrf_token'])) {
|
|
|
|
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rendre le script plus facile à personnaliser avec des variables.
|
|
|
|
$config = include('form_config.php');
|
|
|
|
// Et multilingue !
|
|
|
|
include 'form_lang.php';
|
|
|
|
|
|
|
|
// Fonction pour échapper les sorties
|
|
|
|
function escape($data) {
|
|
|
|
return htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Générer ou récupérer la question antispam
|
|
|
|
if (!isset($_SESSION['current_question']) || isset($_POST['new_question'])) {
|
|
|
|
// Choisir une question aléatoire
|
|
|
|
$questions_list = array_keys($txt['questions']);
|
|
|
|
$current_question = $questions_list[array_rand($questions_list)];
|
|
|
|
$correct_answers = $txt['questions'][$current_question];
|
|
|
|
|
|
|
|
// Mettre à jour la session avec la question et les réponses acceptées
|
|
|
|
$_SESSION['current_question'] = $current_question;
|
|
|
|
$_SESSION['correct_answers'] = $correct_answers;
|
|
|
|
} else {
|
|
|
|
// Utiliser la question stockée dans la session
|
|
|
|
$current_question = $_SESSION['current_question'];
|
|
|
|
$correct_answers = $_SESSION['correct_answers'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// La partie PHP du formulaire
|
|
|
|
// Récuperation des valeurs en GET ou en POST
|
|
|
|
$try = isset($_GET['try']) ? $_GET['try'] : (isset($_POST['try']) ? $_POST['try'] : '');
|
|
|
|
$nobotv = isset($_GET['nobotv']) ? $_GET['nobotv'] : (isset($_POST['nobotv']) ? $_POST['nobotv'] : '');
|
|
|
|
$nobotc = isset($_GET['nobotc']) ? $_GET['nobotc'] : (isset($_POST['nobotc']) ? $_POST['nobotc'] : '');
|
|
|
|
$nobots = isset($_GET['nobots']) ? $_GET['nobots'] : (isset($_POST['nobots']) ? $_POST['nobots'] : '');
|
|
|
|
|
|
|
|
$nobot = time() . '_' . rand(50000, 60000);
|
|
|
|
|
|
|
|
// Vérifier si la demande est pour une nouvelle question
|
|
|
|
if (isset($_POST['new_question'])) {
|
|
|
|
// Réinitialiser la question actuelle
|
|
|
|
$_SESSION['current_question'] = null;
|
|
|
|
$_SESSION['correct_answers'] = null;
|
|
|
|
// Rediriger pour éviter la soumission de formulaire inutile
|
2024-09-12 07:57:14 +00:00
|
|
|
header("Location: #answer");
|
2024-09-11 13:06:40 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($try == 'send') {
|
|
|
|
// Vérifier le token CSRF
|
|
|
|
if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) {
|
2024-09-12 07:57:14 +00:00
|
|
|
echo "<span class=\"spam\">";
|
2024-09-11 13:06:40 +00:00
|
|
|
echo $txt['csrf_error'];
|
2024-09-12 07:57:14 +00:00
|
|
|
echo "</span>";
|
|
|
|
return ;
|
2024-09-11 13:06:40 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ici Le visiteur soumet le formulaire
|
|
|
|
if (($nobotc != md5($nobotv)) || ($nobotv == '') || ($nobots != '')) {
|
2024-09-12 07:57:14 +00:00
|
|
|
echo "<span class=\"spam\">";
|
|
|
|
echo $txt['antispam_error'];
|
|
|
|
echo "</span>";
|
|
|
|
return ;
|
2024-09-11 13:06:40 +00:00
|
|
|
} else {
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
|
|
$name = strip_tags(trim($_POST["name"]));
|
|
|
|
$email = filter_var(trim($_POST["email"]), FILTER_VALIDATE_EMAIL);
|
|
|
|
$subject = strip_tags(trim($_POST["subject"]));
|
|
|
|
$message = strip_tags(trim($_POST["message"]));
|
|
|
|
$user_answer = isset($_POST['answer']) ? trim($_POST['answer']) : '';
|
|
|
|
|
|
|
|
// Validation des données
|
|
|
|
if (empty($name) || empty($email) || empty($subject) || empty($message) || empty($user_answer)) {
|
2024-09-12 07:57:14 +00:00
|
|
|
echo "<span class=\"spam\">";
|
2024-09-11 13:06:40 +00:00
|
|
|
echo $txt['required_fields'];
|
2024-09-12 07:57:14 +00:00
|
|
|
echo "</span>";
|
|
|
|
return ; // Réaffiche le formulaire en cas d'erreur
|
2024-09-11 13:06:40 +00:00
|
|
|
} else {
|
|
|
|
// Vérifier la présence de liens : si oui, fin du script
|
|
|
|
if (preg_match('/http(s?):\/\//ism', $message)) {
|
2024-09-12 07:57:14 +00:00
|
|
|
echo "<span class=\"spam\">";
|
2024-09-11 13:06:40 +00:00
|
|
|
echo $txt['link_error'];
|
2024-09-12 07:57:14 +00:00
|
|
|
echo "</span>";
|
|
|
|
return ; // Réaffiche le formulaire en cas d'erreur
|
2024-09-11 13:06:40 +00:00
|
|
|
exit(); // Arrêter l'exécution si un lien est trouvé
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vérifier la présence de mots-clés
|
|
|
|
$bad_words = $config['bad_words'];
|
|
|
|
foreach ($bad_words as $bad) {
|
|
|
|
if (stripos($message, $bad) !== false) {
|
2024-09-12 07:57:14 +00:00
|
|
|
echo "<span class=\"spam\">";
|
2024-09-11 13:06:40 +00:00
|
|
|
echo $txt['bad_word_error'];
|
2024-09-12 07:57:14 +00:00
|
|
|
echo "</span>";
|
|
|
|
return ; // Réaffiche le formulaire en cas d'erreur
|
2024-09-11 13:06:40 +00:00
|
|
|
exit(); // Arrêter l'exécution si un mot interdit est trouvé
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vérifier la réponse à la question antispam
|
|
|
|
if (isset($_POST['submit_form'])) {
|
|
|
|
if (!empty($user_answer) && in_array(strtolower($user_answer), array_map('strtolower', $correct_answers))) {
|
|
|
|
echo $txt['good_answer'];
|
|
|
|
unset($_SESSION['current_question']);
|
|
|
|
unset($_SESSION['correct_answers']);
|
|
|
|
// Envoi de l'e-mail
|
|
|
|
$to = $config['email']; // Remplacez par votre adresse e-mail
|
|
|
|
$subject_prefix = $config['subject_prefix'];
|
|
|
|
$subjectreal = "$subject_prefix : $subject";
|
|
|
|
$headers = "From: $name <$email>";
|
|
|
|
if (mail($to, $subjectreal, $message, $headers)) {
|
|
|
|
echo $txt['email_success'];
|
|
|
|
} else {
|
|
|
|
echo $txt['email_error'];
|
|
|
|
}
|
|
|
|
} else {
|
2024-09-12 07:57:14 +00:00
|
|
|
echo "<span class=\"spam\">";
|
2024-09-11 13:06:40 +00:00
|
|
|
echo $txt['bad_answer'];
|
2024-09-12 07:57:14 +00:00
|
|
|
echo "</span>";
|
|
|
|
return ; // Réaffiche le formulaire en cas d'erreur
|
2024-09-11 13:06:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|