找回密码
 注册

QQ登录

只需一步,快速开始

【阿里云】2核2G云新老同享 99元/年,续费同价华为云精选云产品特惠做网站就用糖果主机Jtti,新加坡服务器,美国服务器,香港服务器
楼主: 我行我素

[ 收集整理 ] Google SiteMap 生成工具 (PHP & ASP)

[复制链接]
 楼主| 发表于 2005 年 6 月 7 日 22:09:50 | 显示全部楼层

[ 收集整理 ] Google SiteMap 生成工具 (PHP & ASP)

  参数说明:
$website--你的域名
$page_root--你的站点的绝对路径
$changefreq--更新时间单位 "always"(始终), "hourly"(小时), "daily"(天), "weekly"(星期), "monthly"(月), "yearly" "never"(从不)
$priority--更新频率
$allow_dir--允许列表的目录
$disallow_dir--禁止列表的目录
$disallow_file--禁止列表的文件类型

PHP版本
  1. <?php
  2. header('Content-type: application/xml; charset="GB2312"',true);
  3. ?>
  4. <!--
  5. @author 不是我行我素
  6. @version 0.2, 2005-06-06 17:40 PT
  7. @status working
  8. @update Aditya Naik, [email]so1o@so1o.net[/email]
  9. @Licence: LGPL
  10. editor:              [email]bighearted@126.com[/email]
  11. -->
  12. <?php
  13. $website = "[url]http://my.xxxxx.com[/url]"; /* change this */
  14. $page_root = "/usr/local/psa/home/vhosts/subdomains/my/httpdocs";              /* change this */
  15. /* maybe change this: */
  16. $changefreq = "weekly"; //"always", "hourly", "daily", "weekly", "monthly", "yearly" and "never".
  17. $priority = 0.8;
  18. /* this sets the last modification date of all pages to the current date */
  19. $last_modification = date("Y-m-d\TH:i:s") . substr(date("O"),0,3) . ":" . substr(date("O"),3);
  20. /* list of allowed directories */
  21. $allow_dir[] = "web";
  22. /* list of disallowed directories */
  23. $disallow_dir[] = "admin";
  24. $disallow_dir[] = "_notes";
  25. /* list of disallowed file types */
  26. $disallow_file[] = ".inc";
  27. $disallow_file[] = ".old";
  28. $disallow_file[] = ".save";
  29. $disallow_file[] = ".txt";
  30. $disallow_file[] = ".js";
  31. $disallow_file[] = "~";
  32. $disallow_file[] = ".LCK";
  33. $disallow_file[] = ".zip";
  34. $disallow_file[] = ".ZIP";
  35. $disallow_file[] = ".CSV";
  36. $disallow_file[] = ".csv";
  37. $disallow_file[] = ".css";
  38. $disallow_file[] = ".class";
  39. $disallow_file[] = ".jar";
  40. $disallow_file[] = ".mno";
  41. $disallow_file[] = ".bak";
  42. $disallow_file[] = ".lck";
  43. $disallow_file[] = ".BAK";
  44. /* simple compare function: equals */
  45. function ar_contains($key, $array) {
  46.   foreach ($array as $val) {
  47.       if ($key == $val) {
  48.              return true;
  49.       }
  50.   }
  51.   return false;
  52. }
  53. /* better compare function: contains */
  54. function fl_contains($key, $array) {
  55.   foreach ($array as $val) {
  56.       $pos = strpos($key, $val);
  57.       if ($pos === FALSE) continue;
  58.       return true;
  59.   }
  60.   return false;
  61. }
  62. /* this function changes a substring($old_offset) of each array element to $offset */
  63. function changeOffset($array, $old_offset, $offset) {
  64.   $res = array();
  65.   foreach ($array as $val) {
  66.    $res[] = str_replace($old_offset, $offset, $val);
  67.   }
  68.   return $res;
  69. }
  70. /* this walks recursivly through all directories starting at page_root and
  71.   adds all files that fits the filter criterias */
  72. // taken from Lasse Dalegaard, [url]http://php.net/opendir[/url]
  73. function getFiles($directory, $directory_orig = "", $directory_offset="") {
  74.   global $disallow_dir, $disallow_file, $allow_dir;
  75.   if ($directory_orig == "") $directory_orig = $directory;
  76.   if($dir = opendir($directory)) {
  77.       // Create an array for all files found
  78.       $tmp = Array();
  79.       // Add the files
  80.       while($file = readdir($dir)) {
  81.                  // Make sure the file exists
  82.                  if($file != "." && $file != ".." && $file[0] != '.' ) {
  83.               // If it's a directiry, list all files within it
  84.                        //echo "point1<br>";
  85.             if(is_dir($directory . "/" . $file)) {
  86.                              //echo "point2<br>";
  87.                    $disallowed_abs = fl_contains($directory."/".$file, $disallow_dir); // handle directories with pathes
  88.                            $disallowed = ar_contains($file, $disallow_dir); // handle directories only without pathes
  89.                            $allowed_abs = fl_contains($directory."/".$file, $allow_dir);
  90.                            $allowed = ar_contains($file, $allow_dir);
  91.                            if ($disallowed || $disallowed_abs) continue;
  92.                            if ($allowed_abs || $allowed){
  93.                   $tmp2 = changeOffset(getFiles($directory . "/" . $file, $directory_orig, $directory_offset), $directory_orig, $directory_offset);
  94.                   if(is_array($tmp2)) {
  95.                       $tmp = array_merge($tmp, $tmp2);
  96.                   }
  97.                            }
  98.                } else {  // files
  99.                            if (fl_contains($file, $disallow_file)) continue;
  100.                       array_push($tmp, str_replace($directory_orig, $directory_offset, $directory."/".$file));
  101.                      }
  102.                  }
  103.       }
  104.       // Finish off the function
  105.       closedir($dir);
  106.       return $tmp;
  107.   }
  108. }
  109. $a = getFiles($page_root);
  110. echo '<?xml version="1.0" encoding="UTF-8"?>';
  111. ?>
  112. <urlset xmlns="[url]http://www.google.com/schemas/sitemap/0.84[/url]">
  113. <?
  114. foreach ($a as $file) {
  115. ?>
  116.   <url>
  117.      <loc><? echo utf8_encode($website.$file); ?></loc>
  118.      <lastmod><? echo utf8_encode(date("Y-m-d\TH:i:s", filectime($page_root.$file)). substr(date("O"),0,3) . ":" . substr(date("O"),3));?></lastmod>
  119.      <changefreq><? echo utf8_encode($changefreq); ?></changefreq>
  120.      <priority><? echo utf8_encode($priority); ?></priority>
  121.   </url>
  122. <?
  123. }
  124. ?>
  125. </urlset>
复制代码


asp版
  1. <%
  2. ' sitemap_gen.asp
  3. ' A simple script to automatically produce sitemaps for a webserver, in the Google Sitemap Protocol (GSP)
  4. ' by 不是我行我素
  5. ' [url]www.myzykj.com/sitemap[/url]
  6. ' v0.2 released 5 june 2005 (Listing a directory tree recursively improvement)
  7. '
  8. ' BSD 2.0 license,
  9. ' [url]http://www.opensource.org/licenses/bsd-license.php[/url]
  10. ' 收集整理:       [email]bighearted@126.com[/email]
  11. session("server")="[url]http://www.myzykj.com[/url]"                '你的域名
  12. vDir = "/site"                                            '制作SiteMap的目录,相对目录(相对于根目录而言)
  13. set objfso = CreateObject("Scripting.FileSystemObject")
  14. root = Server.MapPath(vDir)
  15. response.ContentType = "text/xml"
  16. response.write "<?xml version='1.0' encoding='UTF-8'?>"
  17. response.write "<urlset xmlns='[url]http://www.google.com/schemas/sitemap/0.84[/url]'>"
  18. Set objFolder = objFSO.GetFolder(root)
  19. 'response.write getfilelink(objFolder.Path,objFolder.dateLastModified)
  20. Set colFiles = objFolder.Files
  21. For Each objFile In colFiles
  22.       response.write getfilelink(objFile.Path,objfile.dateLastModified)
  23. Next
  24. ShowSubFolders(objFolder)
  25. response.write "</urlset>"
  26. set fso = nothing
  27. Sub ShowSubFolders(objFolder)
  28.       Set colFolders = objFolder.SubFolders
  29.       For Each objSubFolder In colFolders
  30.              if folderpermission(objSubFolder.Path) then
  31.                     response.write getfilelink(objSubFolder.Path,objSubFolder.dateLastModified)
  32.                     Set colFiles = objSubFolder.Files
  33.                     For Each objFile In colFiles
  34.                            response.write getfilelink(objFile.Path,objFile.dateLastModified)
  35.                     Next
  36.                     ShowSubFolders(objSubFolder)
  37.              end if
  38.       Next
  39. End Sub
  40. Function getfilelink(file,datafile)
  41.       file=replace(file,root,"")
  42.       file=replace(file,"\","/")
  43.       If FileExtensionIsBad(file) then Exit Function
  44.       if month(datafile)<10 then filedatem="0"
  45.       if day(datafile)<10 then filedated="0"
  46.       filedate=year(datafile)&"-"&filedatem&month(datafile)&"-"&filedated&day(datafile)
  47.       getfilelink = "<url><loc>"&server.htmlencode(session("server")&vDir&file)&"</loc><lastmod>"&filedate&"</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>"
  48.       Response.Flush
  49. End Function
  50. Function Folderpermission(pathName)
  51.       '需要过滤的目录(不列在SiteMap里面)
  52.       PathExclusion=Array("\temp","\_vti_cnf","_vti_pvt","_vti_log","cgi-bin")
  53.       Folderpermission =True
  54.       for each PathExcluded in PathExclusion
  55.              if instr(ucase(pathName),ucase(PathExcluded))>0 then
  56.                     Folderpermission = False
  57.                     exit for
  58.              end if
  59.       next
  60. End Function
  61. Function FileExtensionIsBad(sFileName)
  62.       Dim sFileExtension, bFileExtensionIsValid, sFileExt
  63.       'modify for your file extension ([url]http://www.googleguide.com/file_type.html[/url])
  64.       Extensions = Array("png","gif","jpg","jpeg","zip","pdf","ps","html","htm","asp","php","wk1","wk2","wk3","wk4","wk5","wki","wks","wku","lwp","mw","xls","ppt","doc","swf","wks","wps","wdb","wri","rtf","ans","txt")
  65. '设置列表的文件名,扩展名不在其中的话SiteMap则不会收录该扩展名的文件
  66.       if len(trim(sFileName)) = 0 then
  67.              FileExtensionIsBad = true
  68.              Exit Function
  69.       end if
  70.       sFileExtension = right(sFileName, len(sFileName) - instrrev(sFileName, "."))
  71.       bFileExtensionIsValid = false       'assume extension is bad
  72.       for each sFileExt in extensions
  73.              if ucase(sFileExt) = ucase(sFileExtension) then
  74.                     bFileExtensionIsValid = True
  75.                     exit for
  76.              end if
  77.       next
  78.       FileExtensionIsBad = not bFileExtensionIsValid
  79. End Function
  80. %>
复制代码


按要求设置好,分别保存成PHP或ASP文件
执行生成XML文件,传到服务器上,去
https://www.google.com/webmasters/sitemaps/login

登陆进去以后提交XML地址
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2005 年 6 月 7 日 22:09:50 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价

[ 收集整理 ] Google SiteMap 生成工具 (PHP & ASP)

  参数说明:
$website--你的域名
$page_root--你的站点的绝对路径
$changefreq--更新时间单位 "always"(始终), "hourly"(小时), "daily"(天), "weekly"(星期), "monthly"(月), "yearly" "never"(从不)
$priority--更新频率
$allow_dir--允许列表的目录
$disallow_dir--禁止列表的目录
$disallow_file--禁止列表的文件类型

PHP版本
  1. <?php
  2. header('Content-type: application/xml; charset="GB2312"',true);
  3. ?>
  4. <!--
  5. @author 不是我行我素
  6. @version 0.2, 2005-06-06 17:40 PT
  7. @status working
  8. @update Aditya Naik, [email]so1o@so1o.net[/email]
  9. @Licence: LGPL
  10. editor:              [email]bighearted@126.com[/email]
  11. -->
  12. <?php
  13. $website = "[url]http://my.xxxxx.com[/url]"; /* change this */
  14. $page_root = "/usr/local/psa/home/vhosts/subdomains/my/httpdocs";              /* change this */
  15. /* maybe change this: */
  16. $changefreq = "weekly"; //"always", "hourly", "daily", "weekly", "monthly", "yearly" and "never".
  17. $priority = 0.8;
  18. /* this sets the last modification date of all pages to the current date */
  19. $last_modification = date("Y-m-d\TH:i:s") . substr(date("O"),0,3) . ":" . substr(date("O"),3);
  20. /* list of allowed directories */
  21. $allow_dir[] = "web";
  22. /* list of disallowed directories */
  23. $disallow_dir[] = "admin";
  24. $disallow_dir[] = "_notes";
  25. /* list of disallowed file types */
  26. $disallow_file[] = ".inc";
  27. $disallow_file[] = ".old";
  28. $disallow_file[] = ".save";
  29. $disallow_file[] = ".txt";
  30. $disallow_file[] = ".js";
  31. $disallow_file[] = "~";
  32. $disallow_file[] = ".LCK";
  33. $disallow_file[] = ".zip";
  34. $disallow_file[] = ".ZIP";
  35. $disallow_file[] = ".CSV";
  36. $disallow_file[] = ".csv";
  37. $disallow_file[] = ".css";
  38. $disallow_file[] = ".class";
  39. $disallow_file[] = ".jar";
  40. $disallow_file[] = ".mno";
  41. $disallow_file[] = ".bak";
  42. $disallow_file[] = ".lck";
  43. $disallow_file[] = ".BAK";
  44. /* simple compare function: equals */
  45. function ar_contains($key, $array) {
  46.   foreach ($array as $val) {
  47.       if ($key == $val) {
  48.              return true;
  49.       }
  50.   }
  51.   return false;
  52. }
  53. /* better compare function: contains */
  54. function fl_contains($key, $array) {
  55.   foreach ($array as $val) {
  56.       $pos = strpos($key, $val);
  57.       if ($pos === FALSE) continue;
  58.       return true;
  59.   }
  60.   return false;
  61. }
  62. /* this function changes a substring($old_offset) of each array element to $offset */
  63. function changeOffset($array, $old_offset, $offset) {
  64.   $res = array();
  65.   foreach ($array as $val) {
  66.    $res[] = str_replace($old_offset, $offset, $val);
  67.   }
  68.   return $res;
  69. }
  70. /* this walks recursivly through all directories starting at page_root and
  71.   adds all files that fits the filter criterias */
  72. // taken from Lasse Dalegaard, [url]http://php.net/opendir[/url]
  73. function getFiles($directory, $directory_orig = "", $directory_offset="") {
  74.   global $disallow_dir, $disallow_file, $allow_dir;
  75.   if ($directory_orig == "") $directory_orig = $directory;
  76.   if($dir = opendir($directory)) {
  77.       // Create an array for all files found
  78.       $tmp = Array();
  79.       // Add the files
  80.       while($file = readdir($dir)) {
  81.                  // Make sure the file exists
  82.                  if($file != "." && $file != ".." && $file[0] != '.' ) {
  83.               // If it's a directiry, list all files within it
  84.                        //echo "point1<br>";
  85.             if(is_dir($directory . "/" . $file)) {
  86.                              //echo "point2<br>";
  87.                    $disallowed_abs = fl_contains($directory."/".$file, $disallow_dir); // handle directories with pathes
  88.                            $disallowed = ar_contains($file, $disallow_dir); // handle directories only without pathes
  89.                            $allowed_abs = fl_contains($directory."/".$file, $allow_dir);
  90.                            $allowed = ar_contains($file, $allow_dir);
  91.                            if ($disallowed || $disallowed_abs) continue;
  92.                            if ($allowed_abs || $allowed){
  93.                   $tmp2 = changeOffset(getFiles($directory . "/" . $file, $directory_orig, $directory_offset), $directory_orig, $directory_offset);
  94.                   if(is_array($tmp2)) {
  95.                       $tmp = array_merge($tmp, $tmp2);
  96.                   }
  97.                            }
  98.                } else {  // files
  99.                            if (fl_contains($file, $disallow_file)) continue;
  100.                       array_push($tmp, str_replace($directory_orig, $directory_offset, $directory."/".$file));
  101.                      }
  102.                  }
  103.       }
  104.       // Finish off the function
  105.       closedir($dir);
  106.       return $tmp;
  107.   }
  108. }
  109. $a = getFiles($page_root);
  110. echo '<?xml version="1.0" encoding="UTF-8"?>';
  111. ?>
  112. <urlset xmlns="[url]http://www.google.com/schemas/sitemap/0.84[/url]">
  113. <?
  114. foreach ($a as $file) {
  115. ?>
  116.   <url>
  117.      <loc><? echo utf8_encode($website.$file); ?></loc>
  118.      <lastmod><? echo utf8_encode(date("Y-m-d\TH:i:s", filectime($page_root.$file)). substr(date("O"),0,3) . ":" . substr(date("O"),3));?></lastmod>
  119.      <changefreq><? echo utf8_encode($changefreq); ?></changefreq>
  120.      <priority><? echo utf8_encode($priority); ?></priority>
  121.   </url>
  122. <?
  123. }
  124. ?>
  125. </urlset>
复制代码


asp版
  1. <%
  2. ' sitemap_gen.asp
  3. ' A simple script to automatically produce sitemaps for a webserver, in the Google Sitemap Protocol (GSP)
  4. ' by 不是我行我素
  5. ' [url]www.myzykj.com/sitemap[/url]
  6. ' v0.2 released 5 june 2005 (Listing a directory tree recursively improvement)
  7. '
  8. ' BSD 2.0 license,
  9. ' [url]http://www.opensource.org/licenses/bsd-license.php[/url]
  10. ' 收集整理:       [email]bighearted@126.com[/email]
  11. session("server")="[url]http://www.myzykj.com[/url]"                '你的域名
  12. vDir = "/site"                                            '制作SiteMap的目录,相对目录(相对于根目录而言)
  13. set objfso = CreateObject("Scripting.FileSystemObject")
  14. root = Server.MapPath(vDir)
  15. response.ContentType = "text/xml"
  16. response.write "<?xml version='1.0' encoding='UTF-8'?>"
  17. response.write "<urlset xmlns='[url]http://www.google.com/schemas/sitemap/0.84[/url]'>"
  18. Set objFolder = objFSO.GetFolder(root)
  19. 'response.write getfilelink(objFolder.Path,objFolder.dateLastModified)
  20. Set colFiles = objFolder.Files
  21. For Each objFile In colFiles
  22.       response.write getfilelink(objFile.Path,objfile.dateLastModified)
  23. Next
  24. ShowSubFolders(objFolder)
  25. response.write "</urlset>"
  26. set fso = nothing
  27. Sub ShowSubFolders(objFolder)
  28.       Set colFolders = objFolder.SubFolders
  29.       For Each objSubFolder In colFolders
  30.              if folderpermission(objSubFolder.Path) then
  31.                     response.write getfilelink(objSubFolder.Path,objSubFolder.dateLastModified)
  32.                     Set colFiles = objSubFolder.Files
  33.                     For Each objFile In colFiles
  34.                            response.write getfilelink(objFile.Path,objFile.dateLastModified)
  35.                     Next
  36.                     ShowSubFolders(objSubFolder)
  37.              end if
  38.       Next
  39. End Sub
  40. Function getfilelink(file,datafile)
  41.       file=replace(file,root,"")
  42.       file=replace(file,"\","/")
  43.       If FileExtensionIsBad(file) then Exit Function
  44.       if month(datafile)<10 then filedatem="0"
  45.       if day(datafile)<10 then filedated="0"
  46.       filedate=year(datafile)&"-"&filedatem&month(datafile)&"-"&filedated&day(datafile)
  47.       getfilelink = "<url><loc>"&server.htmlencode(session("server")&vDir&file)&"</loc><lastmod>"&filedate&"</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>"
  48.       Response.Flush
  49. End Function
  50. Function Folderpermission(pathName)
  51.       '需要过滤的目录(不列在SiteMap里面)
  52.       PathExclusion=Array("\temp","\_vti_cnf","_vti_pvt","_vti_log","cgi-bin")
  53.       Folderpermission =True
  54.       for each PathExcluded in PathExclusion
  55.              if instr(ucase(pathName),ucase(PathExcluded))>0 then
  56.                     Folderpermission = False
  57.                     exit for
  58.              end if
  59.       next
  60. End Function
  61. Function FileExtensionIsBad(sFileName)
  62.       Dim sFileExtension, bFileExtensionIsValid, sFileExt
  63.       'modify for your file extension ([url]http://www.googleguide.com/file_type.html[/url])
  64.       Extensions = Array("png","gif","jpg","jpeg","zip","pdf","ps","html","htm","asp","php","wk1","wk2","wk3","wk4","wk5","wki","wks","wku","lwp","mw","xls","ppt","doc","swf","wks","wps","wdb","wri","rtf","ans","txt")
  65. '设置列表的文件名,扩展名不在其中的话SiteMap则不会收录该扩展名的文件
  66.       if len(trim(sFileName)) = 0 then
  67.              FileExtensionIsBad = true
  68.              Exit Function
  69.       end if
  70.       sFileExtension = right(sFileName, len(sFileName) - instrrev(sFileName, "."))
  71.       bFileExtensionIsValid = false       'assume extension is bad
  72.       for each sFileExt in extensions
  73.              if ucase(sFileExt) = ucase(sFileExtension) then
  74.                     bFileExtensionIsValid = True
  75.                     exit for
  76.              end if
  77.       next
  78.       FileExtensionIsBad = not bFileExtensionIsValid
  79. End Function
  80. %>
复制代码


按要求设置好,分别保存成PHP或ASP文件
执行生成XML文件,传到服务器上,去
https://www.google.com/webmasters/sitemaps/login

登陆进去以后提交XML地址
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2005 年 6 月 7 日 22:09:50 | 显示全部楼层

[ 收集整理 ] Google SiteMap 生成工具 (PHP & ASP)

  参数说明:
$website--你的域名
$page_root--你的站点的绝对路径
$changefreq--更新时间单位 "always"(始终), "hourly"(小时), "daily"(天), "weekly"(星期), "monthly"(月), "yearly" "never"(从不)
$priority--更新频率
$allow_dir--允许列表的目录
$disallow_dir--禁止列表的目录
$disallow_file--禁止列表的文件类型

PHP版本
  1. <?php
  2. header('Content-type: application/xml; charset="GB2312"',true);
  3. ?>
  4. <!--
  5. @author 不是我行我素
  6. @version 0.2, 2005-06-06 17:40 PT
  7. @status working
  8. @update Aditya Naik, [email]so1o@so1o.net[/email]
  9. @Licence: LGPL
  10. editor:              [email]bighearted@126.com[/email]
  11. -->
  12. <?php
  13. $website = "[url]http://my.xxxxx.com[/url]"; /* change this */
  14. $page_root = "/usr/local/psa/home/vhosts/subdomains/my/httpdocs";              /* change this */
  15. /* maybe change this: */
  16. $changefreq = "weekly"; //"always", "hourly", "daily", "weekly", "monthly", "yearly" and "never".
  17. $priority = 0.8;
  18. /* this sets the last modification date of all pages to the current date */
  19. $last_modification = date("Y-m-d\TH:i:s") . substr(date("O"),0,3) . ":" . substr(date("O"),3);
  20. /* list of allowed directories */
  21. $allow_dir[] = "web";
  22. /* list of disallowed directories */
  23. $disallow_dir[] = "admin";
  24. $disallow_dir[] = "_notes";
  25. /* list of disallowed file types */
  26. $disallow_file[] = ".inc";
  27. $disallow_file[] = ".old";
  28. $disallow_file[] = ".save";
  29. $disallow_file[] = ".txt";
  30. $disallow_file[] = ".js";
  31. $disallow_file[] = "~";
  32. $disallow_file[] = ".LCK";
  33. $disallow_file[] = ".zip";
  34. $disallow_file[] = ".ZIP";
  35. $disallow_file[] = ".CSV";
  36. $disallow_file[] = ".csv";
  37. $disallow_file[] = ".css";
  38. $disallow_file[] = ".class";
  39. $disallow_file[] = ".jar";
  40. $disallow_file[] = ".mno";
  41. $disallow_file[] = ".bak";
  42. $disallow_file[] = ".lck";
  43. $disallow_file[] = ".BAK";
  44. /* simple compare function: equals */
  45. function ar_contains($key, $array) {
  46.   foreach ($array as $val) {
  47.       if ($key == $val) {
  48.              return true;
  49.       }
  50.   }
  51.   return false;
  52. }
  53. /* better compare function: contains */
  54. function fl_contains($key, $array) {
  55.   foreach ($array as $val) {
  56.       $pos = strpos($key, $val);
  57.       if ($pos === FALSE) continue;
  58.       return true;
  59.   }
  60.   return false;
  61. }
  62. /* this function changes a substring($old_offset) of each array element to $offset */
  63. function changeOffset($array, $old_offset, $offset) {
  64.   $res = array();
  65.   foreach ($array as $val) {
  66.    $res[] = str_replace($old_offset, $offset, $val);
  67.   }
  68.   return $res;
  69. }
  70. /* this walks recursivly through all directories starting at page_root and
  71.   adds all files that fits the filter criterias */
  72. // taken from Lasse Dalegaard, [url]http://php.net/opendir[/url]
  73. function getFiles($directory, $directory_orig = "", $directory_offset="") {
  74.   global $disallow_dir, $disallow_file, $allow_dir;
  75.   if ($directory_orig == "") $directory_orig = $directory;
  76.   if($dir = opendir($directory)) {
  77.       // Create an array for all files found
  78.       $tmp = Array();
  79.       // Add the files
  80.       while($file = readdir($dir)) {
  81.                  // Make sure the file exists
  82.                  if($file != "." && $file != ".." && $file[0] != '.' ) {
  83.               // If it's a directiry, list all files within it
  84.                        //echo "point1<br>";
  85.             if(is_dir($directory . "/" . $file)) {
  86.                              //echo "point2<br>";
  87.                    $disallowed_abs = fl_contains($directory."/".$file, $disallow_dir); // handle directories with pathes
  88.                            $disallowed = ar_contains($file, $disallow_dir); // handle directories only without pathes
  89.                            $allowed_abs = fl_contains($directory."/".$file, $allow_dir);
  90.                            $allowed = ar_contains($file, $allow_dir);
  91.                            if ($disallowed || $disallowed_abs) continue;
  92.                            if ($allowed_abs || $allowed){
  93.                   $tmp2 = changeOffset(getFiles($directory . "/" . $file, $directory_orig, $directory_offset), $directory_orig, $directory_offset);
  94.                   if(is_array($tmp2)) {
  95.                       $tmp = array_merge($tmp, $tmp2);
  96.                   }
  97.                            }
  98.                } else {  // files
  99.                            if (fl_contains($file, $disallow_file)) continue;
  100.                       array_push($tmp, str_replace($directory_orig, $directory_offset, $directory."/".$file));
  101.                      }
  102.                  }
  103.       }
  104.       // Finish off the function
  105.       closedir($dir);
  106.       return $tmp;
  107.   }
  108. }
  109. $a = getFiles($page_root);
  110. echo '<?xml version="1.0" encoding="UTF-8"?>';
  111. ?>
  112. <urlset xmlns="[url]http://www.google.com/schemas/sitemap/0.84[/url]">
  113. <?
  114. foreach ($a as $file) {
  115. ?>
  116.   <url>
  117.      <loc><? echo utf8_encode($website.$file); ?></loc>
  118.      <lastmod><? echo utf8_encode(date("Y-m-d\TH:i:s", filectime($page_root.$file)). substr(date("O"),0,3) . ":" . substr(date("O"),3));?></lastmod>
  119.      <changefreq><? echo utf8_encode($changefreq); ?></changefreq>
  120.      <priority><? echo utf8_encode($priority); ?></priority>
  121.   </url>
  122. <?
  123. }
  124. ?>
  125. </urlset>
复制代码


asp版
  1. <%
  2. ' sitemap_gen.asp
  3. ' A simple script to automatically produce sitemaps for a webserver, in the Google Sitemap Protocol (GSP)
  4. ' by 不是我行我素
  5. ' [url]www.myzykj.com/sitemap[/url]
  6. ' v0.2 released 5 june 2005 (Listing a directory tree recursively improvement)
  7. '
  8. ' BSD 2.0 license,
  9. ' [url]http://www.opensource.org/licenses/bsd-license.php[/url]
  10. ' 收集整理:       [email]bighearted@126.com[/email]
  11. session("server")="[url]http://www.myzykj.com[/url]"                '你的域名
  12. vDir = "/site"                                            '制作SiteMap的目录,相对目录(相对于根目录而言)
  13. set objfso = CreateObject("Scripting.FileSystemObject")
  14. root = Server.MapPath(vDir)
  15. response.ContentType = "text/xml"
  16. response.write "<?xml version='1.0' encoding='UTF-8'?>"
  17. response.write "<urlset xmlns='[url]http://www.google.com/schemas/sitemap/0.84[/url]'>"
  18. Set objFolder = objFSO.GetFolder(root)
  19. 'response.write getfilelink(objFolder.Path,objFolder.dateLastModified)
  20. Set colFiles = objFolder.Files
  21. For Each objFile In colFiles
  22.       response.write getfilelink(objFile.Path,objfile.dateLastModified)
  23. Next
  24. ShowSubFolders(objFolder)
  25. response.write "</urlset>"
  26. set fso = nothing
  27. Sub ShowSubFolders(objFolder)
  28.       Set colFolders = objFolder.SubFolders
  29.       For Each objSubFolder In colFolders
  30.              if folderpermission(objSubFolder.Path) then
  31.                     response.write getfilelink(objSubFolder.Path,objSubFolder.dateLastModified)
  32.                     Set colFiles = objSubFolder.Files
  33.                     For Each objFile In colFiles
  34.                            response.write getfilelink(objFile.Path,objFile.dateLastModified)
  35.                     Next
  36.                     ShowSubFolders(objSubFolder)
  37.              end if
  38.       Next
  39. End Sub
  40. Function getfilelink(file,datafile)
  41.       file=replace(file,root,"")
  42.       file=replace(file,"\","/")
  43.       If FileExtensionIsBad(file) then Exit Function
  44.       if month(datafile)<10 then filedatem="0"
  45.       if day(datafile)<10 then filedated="0"
  46.       filedate=year(datafile)&"-"&filedatem&month(datafile)&"-"&filedated&day(datafile)
  47.       getfilelink = "<url><loc>"&server.htmlencode(session("server")&vDir&file)&"</loc><lastmod>"&filedate&"</lastmod><changefreq>daily</changefreq><priority>1.0</priority></url>"
  48.       Response.Flush
  49. End Function
  50. Function Folderpermission(pathName)
  51.       '需要过滤的目录(不列在SiteMap里面)
  52.       PathExclusion=Array("\temp","\_vti_cnf","_vti_pvt","_vti_log","cgi-bin")
  53.       Folderpermission =True
  54.       for each PathExcluded in PathExclusion
  55.              if instr(ucase(pathName),ucase(PathExcluded))>0 then
  56.                     Folderpermission = False
  57.                     exit for
  58.              end if
  59.       next
  60. End Function
  61. Function FileExtensionIsBad(sFileName)
  62.       Dim sFileExtension, bFileExtensionIsValid, sFileExt
  63.       'modify for your file extension ([url]http://www.googleguide.com/file_type.html[/url])
  64.       Extensions = Array("png","gif","jpg","jpeg","zip","pdf","ps","html","htm","asp","php","wk1","wk2","wk3","wk4","wk5","wki","wks","wku","lwp","mw","xls","ppt","doc","swf","wks","wps","wdb","wri","rtf","ans","txt")
  65. '设置列表的文件名,扩展名不在其中的话SiteMap则不会收录该扩展名的文件
  66.       if len(trim(sFileName)) = 0 then
  67.              FileExtensionIsBad = true
  68.              Exit Function
  69.       end if
  70.       sFileExtension = right(sFileName, len(sFileName) - instrrev(sFileName, "."))
  71.       bFileExtensionIsValid = false       'assume extension is bad
  72.       for each sFileExt in extensions
  73.              if ucase(sFileExt) = ucase(sFileExtension) then
  74.                     bFileExtensionIsValid = True
  75.                     exit for
  76.              end if
  77.       next
  78.       FileExtensionIsBad = not bFileExtensionIsValid
  79. End Function
  80. %>
复制代码


按要求设置好,分别保存成PHP或ASP文件
执行生成XML文件,传到服务器上,去
https://www.google.com/webmasters/sitemaps/login

登陆进去以后提交XML地址
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|金光论坛

GMT+8, 2024 年 10 月 15 日 18:23 , Processed in 0.018528 second(s), 14 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表