Generate Simple Sitemap using PHP

.htaccess (File)

RewriteRule ^sitemap.xml$ sitemap.php [L]

sitemap.php (File)

$connect = mysqli_connect("localhost", "user", "password", "database");
$query = "SELECT username FROM table_name";
$result = mysqli_query($connect, $query);
$base_url = "";
header("Content-Type: application/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL; 
echo '<urlset xmlns="" xmlns:xsi="" xsi:schemaLocation="">' . PHP_EOL;
while($row = mysqli_fetch_array($result))
 echo '<url>' . PHP_EOL;
 echo '<loc>'.$base_url.'/</loc>' . PHP_EOL;
 echo '<changefreq>daily</changefreq>' . PHP_EOL;
 echo '</url>' . PHP_EOL;
echo '</urlset>' . PHP_EOL;

This post was created with our nice and easy submission form. Create your post!

What do you think?


Leave a Reply

Your email address will not be published. Required fields are marked *



How to Add and Delete Users on Ubuntu 16.04 | DigitalOcean