<?php
$host = "localhost"; // host name
$user = "user"; // database user name
$pass = "password"; // database password
$database = "dbname"; // database name
// connecting to database
$connect = @mysql_connect($host,$user,$pass)or die (@mysql_error());
// selecting database
@mysql_select_db($database,$connect) or die (@mysql_error());
// default header(don't delete)
header("Content-Type: text/xml;charset=iso-8859-1");
echo '<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
// mytable = your content table name
$query = @mysql_query("SELECT * FROM mytable");
while($row = @mysql_fetch_array($query)){
// [url] = content url
$url = $row['url'];
// [time] = content date
$date = date("Y-m-d", $row['time']);
// NO CHANGES BELOW
echo
'<url>
<loc>' . $url .'</loc>
<lastmod>'. $date .'</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
';
}
echo '</urlset>';?>
.htaccess code ( Optional )
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*)\.xml(.*) $1.php$2 [nocase]
</IfModule>
No comments:
Post a Comment