User Agent: ' . htmlspecialchars($_SERVER['HTTP_USER_AGENT']) . '
Timestamp: ' . date('Y-m-d H:i:s') . ' UTC
Referrer: ' . htmlspecialchars($_SERVER['HTTP_REFERER'] ?? 'Direct') . '
0, 'time' => time()]; } $data = $_SESSION[$key]; // Reset counter if more than 1 hour has passed if (time() - $data['time'] > 3600) { $_SESSION[$key] = ['count' => 0, 'time' => time()]; $data = $_SESSION[$key]; } // Allow max 5 submissions per hour if ($data['count'] >= 5) { return false; } return true; } // Input validation and sanitization function validateInput($data, $type = 'text') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data, ENT_QUOTES, 'UTF-8'); switch ($type) { case 'email': return filter_var($data, FILTER_VALIDATE_EMAIL) ? $data : false; case 'phone': return preg_match('/^[\+]?[0-9\s\-\(\)]+$/', $data) ? $data : false; case 'text': return strlen($data) > 0 ? $data : false; case 'message': return strlen($data) >= 10 ? $data : false; default: return $data; } } // Response function function sendResponse($success, $message, $data = null) { $response = [ 'success' => $success, 'message' => $message ]; if ($data !== null) { $response['data'] = $data; } echo json_encode($response); exit; } // Handle POST requests only if ($_SERVER['REQUEST_METHOD'] !== 'POST') { sendResponse(false, 'Invalid request method'); } // Check rate limiting if (!checkRateLimit()) { sendResponse(false, 'Too many requests. Please try again later.'); } // Validate and sanitize inputs $name = validateInput($_POST['name'] ?? '', 'text'); $email = validateInput($_POST['email'] ?? '', 'email'); $company = validateInput($_POST['company'] ?? '', 'text'); $service = validateInput($_POST['service'] ?? '', 'text'); $message = validateInput($_POST['message'] ?? '', 'message'); // Validation $errors = []; if (!$name || strlen($name) < 2) { $errors[] = 'Please enter a valid name (minimum 2 characters)'; } if (!$email) { $errors[] = 'Please enter a valid email address'; } if (!$message) { $errors[] = 'Please provide project details (minimum 10 characters)'; } if (!empty($errors)) { sendResponse(false, implode('. ', $errors)); } // Spam protection - simple honeypot and content filtering if (isset($_POST['website']) && !empty($_POST['website'])) { // Honeypot field filled - likely spam sendResponse(false, 'Spam detected'); } // Check for spam keywords $spamKeywords = ['viagra', 'casino', 'lottery', 'bitcoin', 'forex', 'loan', 'debt', 'pharmacy']; $messageContent = strtolower($message . ' ' . $name . ' ' . $company); foreach ($spamKeywords as $keyword) { if (strpos($messageContent, $keyword) !== false) { sendResponse(false, 'Invalid content detected'); } } // Update rate limit counter $ip = $_SERVER['REMOTE_ADDR']; $key = 'contact_' . md5($ip); $_SESSION[$key]['count']++; // Prepare email content $to = 'info@ukdataservices.co.uk'; $subject = 'New Contact Form Submission - UK Data Services'; // Create HTML email $emailHTML = '
UK Data Services
UK Data Services
Dear ' . htmlspecialchars($name) . ',
Thank you for contacting UK Data Services. We have received your inquiry and one of our data specialists will review your requirements and respond within 24 hours.
• Our team will analyse your data requirements
• We will prepare a customised solution proposal
• You will receive a detailed quote and timeline
• We can schedule a consultation call if needed
In the meantime, feel free to:
We look forward to helping you transform your business with professional data solutions.
Best regards,
The UK Data Services Team