diff --git a/contact.php b/contact.php index 7ff51dd..69a8746 100644 --- a/contact.php +++ b/contact.php @@ -9,6 +9,50 @@ include_once $URlcorrection . "includes/header.php"; include_once $URlcorrection . "includes/nav.php"; include_once $URlcorrection . "includes/banner.php"; + +// Generate a new CAPTCHA question if not set +if (!isset($_SESSION['captcha'])) { + $_SESSION['captcha'] = [ + 'num1' => rand(1, 10), + 'num2' => rand(1, 10), + 'answer' => 0 // This will be calculated later + ]; + $_SESSION['captcha']['answer'] = $_SESSION['captcha']['num1'] + $_SESSION['captcha']['num2']; +} + +// Check if form is submitted +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $name = trim($_POST['name']); + $email = trim($_POST['email']); + $subject = trim($_POST['subject']); + $message = trim($_POST['message']); + $captcha_input = isset($_POST['captcha']) ? (int)$_POST['captcha'] : 0; + + // Validate CAPTCHA + if ($captcha_input !== $_SESSION['captcha']['answer']) { + echo "