设为首页 - 加入收藏
广告 1000x90
您的当前位置:主页 > 网站运营 > 正文

自动生成sitemap地图PHP代码

来源:网络分享 编辑:引流技巧 时间:2025-08-31

动生成sitemap地图php代码,无需调用数据库,适用于百度站长提交,需要php的环境,本代码是通过php运行的。

代码如下:

  • <?php 
  • $dom = new DOMDocument("1.0""utf-8"); 
  • header("Content-Type: text/xml"); 
  • $root = $dom->createElement("urlset"); 
  • $dom->appendChild($root); 
  • for ($i = 0; $i <= 998; $i++) { 
  •     $track = $dom->createElement("url"); 
  •     $root->appendChild($track); 
  •     $loc = $dom->createElement("loc"); 
  •     $track->appendChild($loc); 
  •     $lastmod = $dom->createElement("lastmod"); 
  •     $track->appendChild($lastmod); 
  •     $changefreq = $dom->createElement("changefreq"); 
  •     $track->appendChild($changefreq); 
  •     $priority = $dom->createElement("priority"); 
  •     $track->appendChild($priority); 
  •     $text = $dom->createTextNode('https://www.zzvips.com/' . (mt_rand(1,20)) . ($i+1) . '.html'); 
  •     $loc->appendChild($text); 
  •     $date = date("Y-m-d", strtotime('-' . rand(0,10) . 'day')); 
  •     $text = $dom->createTextNode($date); 
  •     $lastmod->appendChild($text); 
  •     $text = $dom->createTextNode(daily); 
  •     $changefreq->appendChild($text); 
  •     $text = $dom->createTextNode(0.8); 
  •     $priority->appendChild($text); 
  • $dom->save("sitemap.xml"); 
  • exit; 
  • 代码参数说明

    changefreq:页面内容更新频率。

    lastmod:页面最后修改时间

    loc:页面永久链接地址

    priority:相对于其他页面的优先权

    百度站长的抓取频率自己设置,然后吧这个链接加入到你的宝塔计划任务定时访问url

    这样他就会自动帮你更新了,这个当然你也可以自己修改一下自己需要的参数或URL

    具体方法请参考百度,已经与百度达成了深度合作,问他都会答你的

    相关推荐:

    栏目分类

    微商引流技巧网 www.yinliujiqiao.com 联系QQ:1716014443 邮箱:1716014443@qq.com

    Copyright © 2019-2024 强大传媒 吉ICP备19000289号-9 网站地图 rss地图

    Top