Sitemap无法显示空白页面

时间:2018-07-24 04:43:00

标签: php sitemap

我的站点地图无法正常运行时,我的站点地图显示空白页面

这是我的站点地图代码,关键字是主表名称,并检查表structure的图像

        <?php
          require dirname(__FILE__) . ("/includes/includes.php");
         header("Content-Type: text/xml");
        print "<?xml version='1.0' encoding='utf-8'?>";
         $pageLimit = 50000;
      $base = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
       $base = substr($base,0,strrpos($base,"/")+1);
        $link = mysql_connect($db_host,$db_user,$db_pass);
       mysql_select_db($db_name,$link); 
        if (isset($_GET["page"]))
         {
print "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd'>";
$page = intval($_GET["page"]);
$from = (($page-1)*$pageLimit);
$sql = "SELECT * FROM keywords LIMIT ".$from.",".$pageLimit;
$result = mysql_unbuffered_query($sql,$link);
while($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
  print "<url>";
  print "<loc>".genSearchUrl(implode('-',array_filter(explode('-', str_replace(' ', '-', xmlentities(iconv("utf-8", "utf-8//ignore", $row["keyword"])))))))."</loc>";      
  print "</url>";
}
print "</urlset>";
 }
  else
  {
print "<sitemapindex xmlns='http://www.google.com/schemas/sitemap/0.84' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/siteindex.xsd'>";
$sql = "SELECT count(*) as count FROM keywords";
$result = mysql_query($sql,$link);
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$pages = ceil($row["count"] / $pageLimit);
for($i=1;$i<=$pages;$i++)
{
  print "<sitemap>";
  $loc = $base."sitemap.php?page=".$i;
  print "<loc>".$web_path."sitemap_".$i.".xml</loc>";
  print "</sitemap>";
}
print "</sitemapindex>";
  }
  exit();
  function xmlentities($text)
 {
$search = array('&','<','>','"','\'');
$replace = array('&amp;','&lt;','&gt;','&quot;','&apos;');
$text = str_replace($search,$replace,$text);
return $text;
}
?> 

0 个答案:

没有答案
相关问题