'OpenAI GPTBot', 'OAI-SearchBot' => 'OpenAI Search', 'ChatGPT-User' => 'ChatGPT (canli)', 'ClaudeBot' => 'Anthropic Claude', 'anthropic-ai' => 'Anthropic', 'Claude-Web' => 'Claude Web', 'PerplexityBot' => 'Perplexity', 'Perplexity-User' => 'Perplexity (canli)', 'Google-Extended' => 'Google Gemini', 'CCBot' => 'Common Crawl', 'Applebot-Extended' => 'Apple AI', 'meta-externalagent'=> 'Meta AI', 'Amazonbot' => 'Amazon AI', 'Bytespider' => 'ByteDance (engelli)', 'YouBot' => 'You.com', 'cohere-ai' => 'Cohere', 'Diffbot' => 'Diffbot', ]; $matched = null; foreach ($ai_bots as $sig => $label) { if (stripos($ua, $sig) !== false) { $matched = $label; break; } } if ($matched === null) return; // AI bot degil -> cik (insan trafigi) $log_file = __DIR__ . '/data/ai_bot_log.json'; $today = date('Y-m-d'); $path = $_SERVER['REQUEST_URI'] ?? '/'; // Query string'i temizle $path = strtok($path, '?'); $fp = @fopen($log_file, 'c+'); if (!$fp) return; if (!flock($fp, LOCK_EX)) { fclose($fp); return; } $raw = stream_get_contents($fp); $data = json_decode($raw, true); if (!is_array($data)) { $data = ['toplam' => 0, 'botlar' => [], 'gunler' => [], 'son_ziyaretler' => []]; } // Toplam + bot bazli $data['toplam'] = ($data['toplam'] ?? 0) + 1; $data['botlar'][$matched] = ($data['botlar'][$matched] ?? 0) + 1; // Gunluk if (!isset($data['gunler'][$today])) $data['gunler'][$today] = []; $data['gunler'][$today][$matched] = ($data['gunler'][$today][$matched] ?? 0) + 1; // Son 50 ziyaret (en yeni basta) array_unshift($data['son_ziyaretler'], [ 'bot' => $matched, 'sayfa' => $path, 'zaman' => date('Y-m-d H:i:s'), ]); $data['son_ziyaretler'] = array_slice($data['son_ziyaretler'], 0, 50); // Gunler listesini son 90 gunle sinirla if (count($data['gunler']) > 90) { krsort($data['gunler']); $data['gunler'] = array_slice($data['gunler'], 0, 90, true); } ftruncate($fp, 0); rewind($fp); fwrite($fp, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); fflush($fp); flock($fp, LOCK_UN); fclose($fp); } catch (\Throwable $e) { // Sessiz - takip hatasi siteyi ETKILEMEZ } })(); // ── Loglama bitti: istenen HTML dosyasini bota sun ── // .htaccess rewrite ?ai_path=... ile gercek dosya yolunu gecirir $req = $_GET['ai_path'] ?? ($_SERVER['REQUEST_URI'] ?? '/'); $req = strtok($req, '?'); $req = ltrim($req, '/'); if ($req === '' ) $req = 'index.html'; // Guvenlik: dizin disina cikma (path traversal) engelle $req = str_replace(['..', "\0"], '', $req); $file = __DIR__ . '/' . $req; // Sadece var olan, website kokunde, .html/.txt/.xml dosyalari $real = realpath($file); $root = realpath(__DIR__); if ($real && $root && strpos($real, $root) === 0 && is_file($real) && preg_match('/\.(html?|txt|xml|json)$/i', $real)) { $ext = strtolower(pathinfo($real, PATHINFO_EXTENSION)); $types = ['html'=>'text/html','htm'=>'text/html','txt'=>'text/plain','xml'=>'application/xml','json'=>'application/json']; header('Content-Type: ' . ($types[$ext] ?? 'text/html') . '; charset=utf-8'); readfile($real); } else { http_response_code(404); $f404 = __DIR__ . '/404.html'; if (is_file($f404)) { header('Content-Type: text/html; charset=utf-8'); readfile($f404); } } exit;