<?php
$ip_address = $_SERVER['REMOTE_ADDR'];
$time_limit = 60; // Time limit in seconds
$max_attempts = 5; // Maximum number of attempts allowed
// Connect to the database
$conn = new mysqli('hostname', 'username', 'password', 'database');
// Check if the IP address exists in the database
$query = "SELECT * FROM submissions WHERE ip_address = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param('s', $ip_address);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$last_attempt = strtotime($row['last_attempt']);
$attempts = $row['attempts'];
if (time() - $last_attempt < $time_limit) {
if ($attempts >= $max_attempts) {
die('You have exceeded the maximum number of submissions. Please try again later.');
} else {
$attempts++;
$query = "UPDATE submissions SET attempts = ?, last_attempt = NOW() WHERE ip_address = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param('is', $attempts, $ip_address);
$stmt->execute();
}
} else {
$query = "UPDATE submissions SET attempts = 1, last_attempt = NOW() WHERE ip_address = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param('s', $ip_address);
$stmt->execute();
}
} else {
$query = "INSERT INTO submissions (ip_address, attempts, last_attempt) VALUES (?, 1, NOW())";
$stmt = $conn->prepare($query);
$stmt->bind_param('s', $ip_address);
$stmt->execute();
}
// Proceed with sending the email
mail($to, $subject, $message, $headers);
?>