Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
session_start();
$rateLimitInterval = 60;
$lastSubmissionTime = isset($_SESSION['last_submission_time']) ? $_SESSION['last_submission_time'] : 0;
$currentTime = time();
if ($currentTime - $lastSubmissionTime < $rateLimitInterval) {
die("Rate limit exceeded. Please try again later.");
}
$_SESSION['last_submission_time'] = $currentTime;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$message = $_POST['message'];
$timestamp = date('Y-m-d H:i:s'); // Capture timestamp
// File Upload Handling
$targetDirectory = "uploads/"; // Specify target directory
$imagePath = null;
if (isset($_FILES["image"]) && $_FILES["image"]["error"] == UPLOAD_ERR_OK) {
$targetFile = $targetDirectory . basename($_FILES["image"]["name"]);
if (move_uploaded_file($_FILES["image"]["tmp_name"], $targetFile)) {
$imagePath = $targetFile;
}
}
$servername = "localhost";
$username = "klas4s23_586004";
$password = "werOiZlV";
$dbname = "klas4s23_586004";
try {
$dsn = "mysql:host=$servername;dbname=$dbname";
$conn = new PDO($dsn, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO entries (name, message, image_path, timestamp) VALUES (:name, :message, :image_path, :timestamp)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':message', $message);
$stmt->bindParam(':image_path', $imagePath);
$stmt->bindParam(':timestamp', $timestamp);
$stmt->execute();
$newEntryId = $conn->lastInsertId();
$newEntry = array("id" => $newEntryId, "name" => $name, "message" => $message, "image_path" => $imagePath, "timestamp" => $timestamp);
die;
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
}
header('Location: /Gastenboek');
?>