prepare("SELECT * FROM api_keys WHERE api_key = ? AND is_active = TRUE"); $stmt->execute([$api_key]); $key_data = $stmt->fetch(); if ($key_data) { return true; } } return false; } function logWebhook($endpoint, $body, $status_code) { $headers = getallheaders(); $ip_address = $_SERVER['REMOTE_ADDR'] ?? null; try { $stmt = db()->prepare("INSERT INTO webhook_logs (endpoint, request_headers, request_body, response_status, ip_address) VALUES (?, ?, ?, ?, ?)"); $stmt->execute([ $endpoint, json_encode($headers), $body, $status_code, $ip_address ]); } catch (PDOException $e) { error_log("Failed to log webhook request: " . $e->getMessage()); } } function sendJsonResponse($data, $statusCode = 200) { header('Content-Type: application/json'); http_response_code($statusCode); echo json_encode($data); exit; } // Create the $pdo variable for scripts that need it. $pdo = db();