SITEMAP GENERATOR IN XML AND TXT

Copy the code below into your php editor, customise as indicated and open the page you have created in your browser.

<script language="php"> /* INSTRUCTIONS Save this to your website having customised it in the top sections to meet your needs. Open it from your browser and the sitemap is created automatically also showing you what has been written. Then it is advisable to get Google to check it by forcing a reload in the google webmaster tools Depending on your server's setting, you may need to chmod the files so the script can access them with file_put_contents If you use this please leave an acknowledgement, ideally a link to my site www.club-host.com or just leave in the comment below */ /* IF YOU WANT TO HAVE PAGES INDEXED WITH THE ? EXTENSIONS UNESCAPE THIS SECTION AND COMPLETE FOR YOUR DATABASE SETUP // CONNECT TO YOUR DATABASE require_once('mysql.php'); // FILL AN ARRAY WITH ID NUMBERS $query = "SELECT `id` FROM `yourdatabase`.`yourtable` ORDER BY id ASC"; $result = mysql_query($query) or mysql_error(); $numresults = mysql_num_rows($result); for ($i=1; $i <=$numresults; $i++) { $row = mysql_fetch_assoc($result); $your_id[] = $row['id']; } // AMEND THE NEXT ROW TO LIST THE PAGES TO WHICH THIS // SECTION APPLIES WITH A SPACE BETWEEN EACH $multiples = "core.php map.php times.php"; */ // DECIDE WHICH PAGES ARE A PRIORITY - NOTE THIS IS RELATIVE // ONLY INSIDE YOUR SITE, SO ALL 1'S (THE HIGHEST) IS USELESS $priority1 = "index.php"; $priority2 = array("about.php","contact.php","whatever.html"); //ADD ANY PAGES TO THIS ARRAY YOU DO NOT WANT IN THE SITEMAP $excludes = array( "favicon.ico", "sitemapgenerator.php", "robots.txt", ".htaccess", "etc.php"); // SET THIS TO THE NAME OF THE SITE $yrsite = "http:/www.whateveritiscalled.com"; // YOU SHOULD HAVE FINISHED CUSTOMISING NOW SO SAVE AND TRY $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <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\">\n"; $results = array(); // $handler = opendir("../"); while ($file = readdir($handler)) { if($file <> "." && $file <> ".." && strstr($file,".") && !in_array($file,$excludes) ) {$results[] = $file;} } closedir($handler); foreach($results AS $k => $v) { $filedetails = stat("../".$v); $lastmod = date("Y-m-d",$filedetails['mtime']); if($v == "index.php"){ $xml .= "<url>\n <loc>".$yrsite.$v; $txt .= "".$yrsite.$v."\n"; $xml .= "</loc>\n <priority>1.0</priority>\n <lastmod>".$lastmod."</lastmod>\n <changefreq>daily</changefreq>\n</url>\n"; for($i=0; $i<count($town); $i++){ $xml .= "<url>\n <loc>".$yrsite.$v."?resetbase=".$town[$i]; $txt .= "".$yrsite.$v."?resetbase=".$town[$i]."\n"; $xml .= "</loc>\n <priority>0.3</priority>\n <lastmod>".$lastmod."</lastmod>\n <changefreq>weekly</changefreq>\n</url>\n"; $h++; } } elseif(strstr($multiples,$v) && $v <> "." && $v <> ".."){ for($i=1; $i<count($your_id); $i++){ $xml .= "<url>\n <loc>".$yrsite.$v."?id=".$your_id[$i]; $txt .= "".$yrsite.$v."?id=".$your_id[$i]."\n"; $xml .= "</loc>\n <priority>0.5</priority>\n <lastmod>".$lastmod."</lastmod>\n <changefreq>weekly</changefreq>\n</url>\n"; $h++; } } else{ $xml .= "<url>\n <loc>".$yrsite.$v; $txt .= "".$yrsite.$v."\n"; $h++; $xml .= "</loc>\n <priority>"; if ($v == $priority1){ $xml .= "1";} elseif (in_array($v,$priority2)) {$xml .= "0.7";} else {$xml .= "0.4";} $xml .= "</priority>\n <lastmod>".$lastmod."</lastmod>\n <changefreq>daily</changefreq>\n</url>\n"; }} $xml .= "</urlset>"; $h1 = $h * 6 + 8; $h2 = $h + 1 ; $h1 = $h2 = 10; echo " <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> <title>XML SITEMAP GENERATOR &copy; TJSOFT</title> </head> <body> <h1>XML format</h1> <br>\n <textarea cols='100' rows='".$h1."'>\n".$stub_start.$xml.$stub_end."\n</textarea>\n <br> <h1>TXT format</h1><br>\n <textarea cols='100' rows='".$h2."'>\n".$txt."\n</textarea>"; file_put_contents(../sitemap.xml,$stub_start.$xml.$stub_end); file_put_contents(../sitemap.txt,$txt); echo " <h1>If there are no errors above, sitemap.xml and sitemap.txt have been updated.</h1>\n <p>A sample Sitemap that contains just one URL and uses all optional tags is shown below. \n <p><?xml version=\"1.0\" encoding=\"UTF-8\"?>\n < urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">\n < url>\n < loc>http://www.example.com/\n < lastmod>2005-01-01\n < changefreq>monthly\n < priority>0.8\n </p>"; ?> <p>The Sitemap must: <p>* Begin with an opening <urlset> tag and end with a closing </urlset> tag. <p>* Include a <url> entry for each URL as a parent XML tag. <p>* Include a <loc> child entry for each <url> parent tag. <h2>XML tag definitions </h2> <p>The available XML tags are described below. <urlset> required Encapsulates the file and references the current protocol standard. <url> required Parent tag for each URL entry. The remaining tags are children of this tag. <loc> required URL of the page. This URL must begin with the protocol (such as http) and end with a trailing slash, if your web server requires it. This value must be less than 2048 characters. <lastmod> optional The date of last modification of the file. This date should be in W3C Datetime format. This format allows you to omit the time portion, if desired, and use YYYY-MM-DD. <changefreq> optional How frequently the page is likely to change. This value provides general information to search engines and may not correlate exactly to how often they crawl the page. Valid values are: <p>* always * hourly * daily * weekly * monthly * yearly * never <p>The value "always" should be used to describe documents that change each time they are accessed. The value "never" should be used to describe archived URLs. Please note that the value of this tag is considered a hint and not a command. Even though search engine crawlers consider this information when making decisions, they may crawl pages marked "hourly" less frequently than that, and they may crawl pages marked "yearly" more frequently than that. It is also likely that crawlers will periodically crawl pages marked "never" so that they can handle unexpected changes to those pages. <priority> <p>optional <p> The priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0. This value has no effect on your pages compared to pages on other sites, and only lets the search engines know which of your pages you deem most important so they can order the crawl of your pages in the way you would most like. The default priority of a page is 0.5. Please note that the priority you assign to a page has no influence on the position of your URLs in a search engine's result pages. Search engines use this information when selecting between URLs on the same site, so you can use this tag to increase the likelihood that your more important pages are present in a search index. Also, please note that assigning a high priority to all of the URLs on your site will not help you. Since the priority is relative, it is only used to select between URLs on your site; the priority of your pages will not be compared to the priority of pages on other sites. THIS SCRIPT WAS DEVELOPED BY TJSOFT AND IS AVAILABLE FREE AT <a href='http://www.clubhost.com/scripts.php'>WWW.CLUB-HOST.COM</a> <!-- SITEMAP GENERATOR BY TJSOFT - FREE AT WWW.CLUB-HOST.COM --> </script>