| <?php
|
| session_start();
|
| header('Content-Type: application/json');
|
|
|
|
|
|
|
|
|
| if (empty($_SESSION['csrf_token'])) {
|
| $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
| }
|
|
|
|
|
|
|
|
|
| if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
| $response = ['status' => 'error', 'message' => 'Unknown error'];
|
|
|
|
|
| if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) {
|
| http_response_code(403);
|
| $response['message'] = "CSRF validation failed";
|
| echo json_encode($response);
|
| exit;
|
| }
|
|
|
|
|
| $name = htmlspecialchars(trim($_POST['name']));
|
| $email = htmlspecialchars(trim($_POST['email']));
|
| $message = htmlspecialchars(trim($_POST['message']));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| $response = [
|
| 'status' => 'success',
|
| 'message' => 'Email Sent Successfully, Hoorray 🎉🎉🎉!'
|
| ];
|
| echo json_encode($response);
|
| exit;
|
| }
|
|
|
|
|
|
|
|
|
| echo json_encode([
|
| 'csrf_token' => $_SESSION['csrf_token']
|
| ]);
|
| ?>
|
|
|