<?php
header('Content-Type: application/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <?php
    // Dynamically get the site URL from the host
    $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https' : 'http';
    $host = $_SERVER['HTTP_HOST'];
    $site_url = $protocol . '://' . $host;

    // Define your site's URLs here (add more as needed)
    $pages = [
        ['loc' => '/', 'priority' => '1.0', 'changefreq' => 'daily'],
        ['loc' => '/products', 'priority' => '0.8', 'changefreq' => 'weekly'],
        ['loc' => '/about', 'priority' => '0.6', 'changefreq' => 'monthly'],
        ['loc' => '/contact', 'priority' => '0.6', 'changefreq' => 'monthly'],
        // Add dynamic product pages or categories if available, e.g., from a database
    ];

    foreach ($pages as $page) {
        echo '<url>';
        echo '<loc>' . htmlspecialchars($site_url . $page['loc']) . '</loc>';
        echo '<lastmod>' . date('Y-m-d') . '</lastmod>'; // Update with actual last modified date if available
        echo '<changefreq>' . $page['changefreq'] . '</changefreq>';
        echo '<priority>' . $page['priority'] . '</priority>';
        echo '</url>';
    }
    ?>
</urlset>