<?php
/**
 * Place this in your public/ folder and run it via browser.
 * e.g., https://bdcrimewatch.com/check_headers.php
 */

$targets = [
    'Self Robots' => 'https://' . $_SERVER['HTTP_HOST'] . '/robots.txt',
    'Main Sitemap' => 'https://dhakasupplier2.com/sitemap.xml'
];

echo "<h2>Server Header & Connectivity Check</h2>";

foreach ($targets as $name => $url) {
    echo "<h3>Checking $name: <code>$url</code></h3>";
    
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_NOBODY, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)');

    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);

    if ($info['http_code'] == 200) {
        echo "<p style='color:green;'>✅ Success (HTTP 200)</p>";
        echo "<pre style='background:#f4f4f4; padding:10px; border:1px solid #ccc;'>" . htmlspecialchars($response) . "</pre>";
    } else {
        echo "<p style='color:red;'>❌ Error: Received HTTP " . $info['http_code'] . "</p>";
    }
    echo "<hr>";
}
?>