Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a sitemap using PHP & MySQL

Tags:

php

mysql

sitemap

I was wondering how can I create a sitemap using PHP & MySQL and is there any sitemap design examples you know of?

like image 575
HELP Avatar asked Oct 25 '10 21:10

HELP


People also ask

What is PHP sitemap?

In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL (when it was last updated, how often it usually changes, and how important it is, relative to other URLs in the site) so that search engines can more intelligently crawl the site.

Can a sitemap be a PHP file?

Yep, that's right.


1 Answers

I use this on my site, it works well and you can point Google's webmaster tools to "this_file.php" and it works wonders!

<?php
header("Content-type: text/xml");
echo'<?xml version=\'1.0\' encoding=\'UTF-8\'?>';
echo'   <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">';

include '../include.php';
$sql = mysql_query("select blah from bleh");

while ($string = mysql_fetch_array($sql)){?>
            <url>
                <loc>http://www.domain.com/dir/<?echo $string['value'];?>/index.php</loc>
                <changefreq>weekly</changefreq>
            </url>
<?php } ?> 
</urlset>
like image 182
Westy92 Avatar answered Oct 11 '22 03:10

Westy92