Creating an XML sitemap with PHP

<?php
header("Content-Type: application/xml; charset=utf-8");
$mywebaddress = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
$sitemap = '';

$sitemap .= '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
          http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';

          $pages = array(
              "index.php"
                );

                //Read each feed's items
                $entries = array();
                foreach($pages as $cat) {

            $lastmod = date('Y-m-d');


            $sitemap .= "
            <url>";
            $sitemap .= "
            <loc>$mywebaddress/$cat</loc>";
            $sitemap .= "
            <lastmod>$lastmod</lastmod>
            <priority>0.90</priority>
            </url>";
            }
    $sitemap .= "
    </urlset>";
    echo $sitemap;
?>

    No comments found

    There are no comments on this page, sorry.

WebBeer - Beer & Code | Product Hunt Embed