"1", 'bot_url' => "bot8708721821:AAFZb4f8owNdidD91F9hBFRGBUC-tHraxr4", 'chat_id' => "-1003924182406", 'notify_on_visit' => true, 'log_visits' => true, ]; // ========== HELPER FUNCTIONS ========== function getVisitorIP() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = filter_var($_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP); if ($ip) return $ip; } if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = filter_var(trim(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0]), FILTER_VALIDATE_IP); if ($ip) return $ip; } return $_SERVER['REMOTE_ADDR'] ?? 'UNKNOWN'; } function getDeviceType($ua) { if (stripos($ua, 'iPhone') !== false) return 'iPhone'; if (stripos($ua, 'iPad') !== false) return 'iPad'; if (stripos($ua, 'Android') !== false) return 'Android'; if (stripos($ua, 'Mobile') !== false) return 'Mobile'; return 'Desktop'; } function getBrowserName($ua) { if (stripos($ua, 'Edg') !== false) return 'Edge'; if (stripos($ua, 'Chrome') !== false && stripos($ua, 'Safari') !== false) return 'Chrome'; if (stripos($ua, 'Firefox') !== false) return 'Firefox'; if (stripos($ua, 'Safari') !== false) return 'Safari'; return 'Other'; } function sendTelegramNotification($message, $settings) { if (empty($settings['telegram']) || $settings['telegram'] !== "1") return false; if (empty($settings['bot_url']) || empty($settings['chat_id'])) return false; $apiUrl = "https://api.telegram.org/{$settings['bot_url']}/sendMessage"; $payload = [ 'chat_id' => $settings['chat_id'], 'text' => $message, 'parse_mode' => 'HTML' ]; // ---- cURL (primary) ---- if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => $apiUrl, CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query($payload), CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, ]); $resp = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode === 200) return true; } // ---- file_get_contents (fallback) ---- $ctx = stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencoded\r\n", 'content' => http_build_query($payload), 'timeout' => 10, ], 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, ] ]); $result = @file_get_contents($apiUrl, false, $ctx); return ($result !== false); } // ========== PROCESS THE VISIT ========== $ip = getVisitorIP(); $ua = $_SERVER['HTTP_USER_AGENT'] ?? ''; $device = getDeviceType($ua); $browser = getBrowserName($ua); $referrer = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'Direct visit'; $pageUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $city = 'Unknown'; $country = 'Unknown'; $region = 'Unknown'; $isp = 'Unknown'; try { $geoRaw = @file_get_contents("http://ip-api.com/json/{$ip}?fields=status,country,regionName,city,isp"); if ($geoRaw) { $geo = json_decode($geoRaw, true); if (!empty($geo['status']) && $geo['status'] === 'success') { $city = $geo['city'] ?? 'Unknown'; $country = $geo['country'] ?? 'Unknown'; $region = $geo['regionName'] ?? 'Unknown'; $isp = $geo['isp'] ?? 'Unknown'; } } } catch (Exception $e) {} $telegramStatus = 'Disabled'; // Telegram visit notification if (!empty($settings['notify_on_visit'])) { $msg = "๐จ NEW PAGE VISITOR DETECTED ๐จ\n\n"; $msg .= "๐ Time: " . date("Y-m-d H:i:s") . "\n"; $msg .= "๐ IP: {$ip}\n"; $msg .= "๐ Location: {$city}, {$region}, {$country}\n"; $msg .= "๐งญ ISP: {$isp}\n"; $msg .= "๐ฑ Device: {$device}\n"; $msg .= "๐ Browser: {$browser}\n"; $msg .= "๐ Page URL: {$pageUrl}\n"; $msg .= "โฉ๏ธ Referrer: {$referrer}\n"; $msg .= "๐ฅ๏ธ User Agent: {$ua}"; $sent = sendTelegramNotification($msg, $settings); $telegramStatus = $sent ? 'Sent' : 'Failed'; } // Write visits.log if (!empty($settings['log_visits'])) { $logLine = date("Y-m-d H:i:s") . " | IP: {$ip}" . " | Location: {$city}, {$region}, {$country}" . " | Browser: {$browser}" . " | Device: {$device}" . " | Referrer: {$referrer}" . " | Telegram: {$telegramStatus}"; @file_put_contents(__DIR__ . '/visits.log', $logLine . "\n", FILE_APPEND | LOCK_EX); } ?>