PHP Google Search Sitemap Generator Script
You can use this script to create the google sitemap XML for your site automatically. The script will recursively visit all files on your site and create a sitemap XML file in the format needed by Google. This site is targeted at sites with static content.
You can customize the result by changing the starting priorities.
Sitemap Generator Code
Download this file and rename it as 'create_sitemap.php'
Download Google Search Sitemap Generator Script - 8.2 KB
Working of Google Sitemap Generator
First, you have to edit the first few lines of the script to match the setting of your site. The comments explains what needs to be entered. Please note that you have to have a basic understanding of PHP to do this.
After configuring, just run the file every time you make a change to your site. The script will automatically recreate the sitemap - with the new content included.
Configuration
These are the lines that must be edited...
<?php
$url = "http://www.bin-co.com/"; //The Url of the site - the last '/' is needed
$root_dir = '../..'; //Where the root of the site is with relation to this file.
$file_mask = '*.php'; //Or *.html or whatever - Any pattern that can be used in the glob() php function can be used here.
//The file to which the result is written to - must be writable. The file name is relative from root.
$sitemap_file = 'sitemap.xml';
// Stuff to be ignored...
//Ignore the file/folder if these words appear in the name
$always_ignore = array(
'local_common.php','images'
);
//These files will not be linked in the sitemap.
$ignore_files = array(
'404.php','error.php','configuration.php','include.inc'
);
//The script will not enter these folders
$ignore_folders = array(
'Waste','php_uploads','images','includes','lib','js','css','styles','system','stats','CVS','.svn'
);
To Do
This is a beta software - a lot of work need to be done before this can be perfect
License
MIT License

Comments
$starting_priority = ($_REQUEST['starting_priority']) ? $_REQUEST['starting_priority'] : 70;
should be:
$starting_priority = isset($_REQUEST['starting_priority']) ? $_REQUEST['starting_priority'] : 70;
Right?
Did you write this comment script? Are you willing to share?
The email is real.
deeply integrated into the CMS used in that site. I cannot share just the
commenting part. And I have no intention of sharing the full CMS - there are
many CMS that are much better than mine.
Will give it a try and see.
Nice work dude!
downloaded your site generator .I have a problem .When i press create button , the page loaded shows blank.Maybe i did something wrong with file to store information.
Anyway , i uploaded your code to sitemapcreator.php to sitemap folder.The file sitemap.php is also in same folder.Maybe this file should be in some other extension, like .txt . Let me know how i can solve this problem of getting blank page.
I tried your script but everytime I press create sitemap it loads sitemap.php which does not exist on my server.
How do you make this work?
<?php echo "Make sure the following url is correct."
. "
"
. $url
."
If not please edit this page!
" ;
} ?>
Thanks Again,
Benny
i replaced "url/" with "mine/" and it dosent work redirect to my host error page
i think because of root, cant define it exactly ..
but thanks (y).
Thanks.
thanks any ways ur script is cool...
regards
Warning: fopen(sitemap.xml) [function.fopen]: failed to open stream: Permission denied in /home/viart/public_html/sitemap.php on line 107
Can't open sitemap file - 'sitemap.xml'. Dumping result to screen...
Warning: fopen(sitemap.xml) [function.fopen]: failed to open stream: Permission denied in /home/viart/public_html/sitemap.php on line 107
Can't open sitemap file - 'sitemap.xml'. Dumping result to screen...
Warning: Division by zero in /home/viart/public_html/sitemap.php on line 119
Really useful piece of code, using it on a couple of sites currently, I was wondering if it would be possible to get it to output in order of priority?
I've tried a few options to get it to output in priority order but no joy so far, any one have any suggestions or managed to do this?
Thanks
i was looking for a script like this but unfortunately i have no experince in making changes in this kinda code i hope it works as you all said. can anybody let me know step by step that what should i do ... i know it's already written but i don't want to make mess with my forum cause i already had to reinstall i guess more than 25 times and now i'm totally stuck. need just a little help if you can.
Thanks Aj
I love the concept of this script, It's something I have been looking for.
Unfotunately, I get an eror:
XML Parsing Error: no element found
Location: www.rummycity.com/site-map.xml
Line Number 1, Column 44:<?xml version="1.0" encoding="iso-8859-1"?>
-------------------------------------------^
The link to the site map is: www.rummycity.com/site-map.xml
Can you please help me here?
Thanks
i mean, php or asp
You will need to spend some time configuring $always_ignore,$ignore_files and $ignore folders, but apart from that if you know how to chmod a file named sitemap.xml you shouldn't have much trouble.
P.S. If you follow Binny's instructions on naming the file sitemap.php be sure to drop all the way to bottom of the script and change the form action from create_sitemap.php to sitemap.php as Binny forgot to change his code. See my generated sitemap here> RedLineRider Sitemap
What should I change to make it work on dynamic website??
Angelina
Good job on this. I made a few changes so it would fit my particular situation better and will email you those changes for your consideration.
Here are the great things about your script:
1) It's simple and elegant.
2) Not a lot of setup and tweaking needed as with some other scripts.
3) Finds files from the server side instead of by crawling the site (does anyone really believe the sitemap generators that crawl websites have a better crawler than Google?)
Thanks for posting this. You need to post a donate button too! ;)
Regards,
Richard
Hope I helped you.
I tried to tweak $file_mask = '*.php' but can't get it to look for both type of files at once...
I'd appreciate any help.
And thanks a lot to Binny, indeed!
$file_mask = array('*.php','*.html');
else try:
$file_mask = '*.php', '*.html';
or you could try:
$file_mask.= '*.php';
$file_mask.= '*.html';
Kind regards,
Unknown S
I tried feeding it with $file_mask.= '*.php';
$file_mask.= '*.html'; - or both at the same time....
Chmod on sitemap.xml is done...
I tried feeding it with $file_mask.= '*.php';
$file_mask.= '*.html'; - or both at the same time....
Chmod on sitemap.xml is done...
I tried feeding it with $file_mask.= '*.php';
$file_mask.= '*.html'; - or both at the same time....
Chmod on sitemap.xml is done...
When do you plan to do a new version of this. It will be nice to have few new feathures specially a way to remove characters like "&" from the titles of sitemap as google reports an error in sitemap where "&" appears in url or title
Jamal
Change this line to something like this
$file_mask = '*.{php,htm,pdf}'; //Or *.html or whatever - Any pattern that can be used in the glob() php function can be used here.
And then below where it calls glob, add the GLOB_BRACE flag like this:
$files = glob($directory . $GLOBALS['file_mask'], GLOB_BRACE);
Cool script!
a, strong, em, b, i, code, pre, pandbrallowed. Other tags will be shown as code(< will become <). Urls, Line breaks will be auto-formated.