MikroSight.com

MikroSight.com

| Home | NPA/NPX |

Google
Web
MikroSight

Create Site Map Tutorial - Page 3

Create Site Map Tutorial - Page 1
Create Site Map Tutorial - Page 2

Let's start breaking down the code shown on Page 2. The first section is just some variables we need.

  • $siteUrl & $sitePath - used in some basic substitution commands
  • $files is a blank array that will hold the results of our tree traversal
  • $ignore is an array of things to ignore - this can be a file name, directory name, or extension.

$siteUrl & $sitePath are used in substitution commands to convert page names - for example, the file system sees this page as

/home/mikrosight/public_html/tutorials/sitemap/create/page-3.shtml

but to the rest of the world who access this file via http:, the address is

http://www.mikrosight.com/tutorials/sitemap/create/page-3.shtml

<?php

$siteUrl = "http://www.mikrosight.com/";
$sitePath = "/home/mikrosight/public_html/"; //the location of files in the server file system
$files = array();

$ignore = array ('.','..','images', 'cgi-bin','ico','Thumbs.db','jpg', 'JPG', 'gif', 'w3c', 'P3P', 'php', '.htaccess', 'css', 'txt', 'xml', 'mov', 'MOV', 'exe', 'EXE', 'ZIP', 'zip', 'mp3', 'wmv', 'asf', 'tif');

$ignoreIn is another mixed array that contains some things that I wanted to ignore if they are even part of a file name - more on how I use that later, but here is what mine looks like.

  //$ignoreIn is a mixed array of anything you want to ignore that is a partial
//For example, I have lots of pages named target#.html where # is a number from 0-9

$ignoreIn = array ('target');

The following variables are used while writing the sitemap.xml file and are defined in Google's sitemap.xml file definition as documented on their site.

//Valid settings for $freq are: always, hourly, daily, weekly, monthly, yearly, never

$freq = "weekly";
$priority = "0.5";
$lastmodification = true;

The rest of this is for esthetics, debugging and easy access.

//Show dots ... TRUE for dots while creating, FALSE to show each file on a separate line
// great for debugging

$showDots = TRUE;

//the following allows you to put this up on your site - even if someone finds the page
//they would have to know both $_POST parameter names and values to run this script
//and the only adverse affect would be a new sitemap.xml file in your root folder

$mykey = 'MikRo';
$mypass = 'Fun757monKey';

if ( ! (isset($_POST['key'])
        && ($_POST['key'] == $mykey)
        && isset($_POST['pass'])
        && ($_POST['pass'] == $mypass)
       )
     ) { header('Location:' . $siteurl);
}
else {

//default for $showDots is TRUE as defined above
//The following IF construct will check for a $_POST var named dots to override this,
// and if $_POST['dots'] is set to FALSE, it will override the default
//example parameter appended to those shown above &dots=FALSE

if ( !isset($_POST['dots']) ) {
  $showDots = FALSE;
}

Create Site Map Tutorial - Page 4