<?php
// sitemap.php
header('Content-Type: application/xml; charset=utf-8');

// اتصال به دیتابیس
$conn = new mysqli("localhost", "serversm_shopdb", "Milad@1369", "serversm_shopdb");
if ($conn->connect_error) die();

$base_url = "https://serversmart.ir";

echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
    
// صفحه اصلی
echo '<url>';
echo '<loc>'.$base_url.'</loc>';
echo '<lastmod>'.date('Y-m-d').'</lastmod>';
echo '<changefreq>daily</changefreq>';
echo '<priority>1.0</priority>';
echo '</url>';

// دسته‌بندی‌ها
$categories = $conn->query("SELECT id, name, updated_at FROM categories");
while($cat = $categories->fetch_assoc()) {
    echo '<url>';
    echo '<loc>'.$base_url.'/?category='.$cat['id'].'</loc>';
    echo '<lastmod>'.date('Y-m-d', strtotime($cat['updated_at'])).'</lastmod>';
    echo '<changefreq>weekly</changefreq>';
    echo '<priority>0.8</priority>';
    echo '</url>';
}

$conn->close();
echo '</urlset>';
?>