<?php
header('Content-Type: application/json');

// Liste der zu prüfenden User-Agents
$userAgents = [
    'ChatGPT' => 'Mozilla/5.0 (compatible; ChatGPT; OpenAI)',
    'Googlebot' => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
    'Bingbot' => 'Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)',
    'Uschi' => 'Mozilla/5.0 (compatible; UschiBot/1.0; +https://intelectra.de)',
];

$targetUrl = 'https://intelectra.de/sitemap.xml';
$results = [];

foreach ($userAgents as $bot => $ua) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $targetUrl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $connectTime = curl_getinfo($ch, CURLINFO_CONNECT_TIME);
    $totalTime = curl_getinfo($ch, CURLINFO_TOTAL_TIME);
    $error = curl_error($ch);

    $results[$bot] = [
        'user_agent' => $ua,
        'http_code' => $httpCode,
        'connect_time' => $connectTime,
        'total_time' => $totalTime,
        'error' => $error ?: null,
    ];

    curl_close($ch);
}

echo json_encode([
    'target' => $targetUrl,
    'timestamp' => date('c'),
    'results' => $results,
], JSON_PRETTY_PRINT);
