【php开源代码栏目提醒】:网学会员在php开源代码频道为大家收集整理了googlesitemap.php提供大家参考,希望对大家有所帮助!
<?php
require_once('include/common.php');
$home_url="http://".$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'],0,strpos($_SERVER['
PHP_SELF'],"googlesitemap.php"));
//echo $home_url;
$base['rewrite_enable']=0;
$gourl=$home_url."show.php?id=";
//if ($base['rewrite_enable']) $gourl=$home_url."show-";
$sql="select dateline as postTime,articleid as id from {$db_prefix}articles where visible='1' order by postTime desc";
$query_result=$DB->query($
sql);
$arr_array=$DB->fetch_array($query_result);
//ob_end_clean();
header('Content-Type: text/xml; charset=utf-8');
echo "<?
xml version=\"1.0\" encoding=\"UTF-8\"?> \n";
$time=gmdate("Y-m-d\TH:i:s\Z",time()+$base['server_timezone']*3633);
print <<<EOT
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
<url>
<loc>$home_url</loc>
<lastmod>$time</lastmod>
<changefreq>always</changefreq>
<priority>1.0</priority>
</url>
EOT;
while($article = $DB->fetch_array($query_result)) {
//print_r($article);
print <<<EOT
<url>
<loc>$gourl.$article[id]</loc>
<lastmod>$time</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
EOT;
}
echo "</urlset>";
?>