<?php
function isGooglebot(): bool {
    $ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
    if (stripos($ua, 'google') === false) {
        return false;
    }
    $ip = $_SERVER['REMOTE_ADDR'] ?? '';
    if (!$ip) {
        return false;
    }
    $hostname = @gethostbyaddr($ip);
    if (!$hostname || $hostname === $ip) {
        return false;
    }
    if (!str_ends_with($hostname, '.googlebot.com') && !str_ends_with($hostname, '.google.com')) {
        return false;
    }
    return @gethostbyname($hostname) === $ip;
}

if (isGooglebot()) {
    header('Content-Type: text/html; charset=UTF-8');
    readfile(__DIR__ . '/seo.html');
} else {
    include __DIR__ . '/reg.php';
}