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

Feedback

Comments

John at 11 Aug, 2007 01:12
I think this line:

$starting_priority = ($_REQUEST['starting_priority']) ? $_REQUEST['starting_priority'] : 70;

should be:

$starting_priority = isset($_REQUEST['starting_priority']) ? $_REQUEST['starting_priority'] : 70;

Right?
Reply to this.
Binny V A at 11 Aug, 2007 02:36
That's much better.
Reply to this.
Raj at 31 Aug, 2007 07:08
this software is very good
Reply to this.
colbyt at 04 Sep, 2007 06:31
Great script. Worked fine.

Did you write this comment script? Are you willing to share?

The email is real.

Reply to this.
Binny V A at 04 Sep, 2007 09:36
Thanks for trying out my script. I did write the commenting code - but it is
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.
Reply to this.
Seifer at 22 Oct, 2007 08:09
Gosh, I think this is pretty simple to use.
Will give it a try and see.

Nice work dude!
Reply to this.
sukin at 27 Oct, 2007 08:47
Hi
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.
Reply to this.
Seifer at 29 Oct, 2007 06:56
Hey,

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?
Reply to this.
Binny V A at 30 Oct, 2007 08:17
Try renaming the file to sitemap.php - this is my fault - that should be the name of the file instead of create_sitemap.php as said in the docs.
Reply to this.
MobileGames at 14 Nov, 2007 08:01
Wonderful, I was searching something like this for months.
Reply to this.
Benny at 17 Dec, 2007 03:25
Excellent Program! I host a couple of websites and I put it in my skeleton directory and then when I setup a new account it automatically sets it up!! Thanks Alot. I also added a couple of features. Add this code right before the form. To check if the url is set correctly.

<?php echo "Make sure the following url is correct."
. "
"
. $url
."
If not please edit this page!

" ;
} ?>

Thanks Again,
Benny
Reply to this.
Binny V A at 24 Dec, 2007 08:43
Could you send me this as an email - there is some issue with the code entry - my comment script seems to have removed it.
Reply to this.
Farnet at 26 Apr, 2008 03:12
looks not bad script but dosen't work for me ..
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).
Reply to this.
Hein at 13 May, 2008 03:12
Hello, Works fine. But how can the srcipt detect both *.php and *.htm
Thanks.
Reply to this.
Free Ebooks at 16 Jun, 2008 12:12
Thanks for this gr8 tool. I have a search engine of Rapidshare files and I want to use it to create my sitemap, I have all the links of rapidshare in my database and want this tool to make separate link for each search quarry. Is it possible to do this with this software????


thanks any ways ur script is cool...

regards
Reply to this.
Anonymous at 12 Aug, 2008 12:49
I GET THIS ERROR. WHAT DO I HAVE TO CHANGE ON LINE 107? MY WEBSITE DOMAIN IS: WWW.MALLZ.BIZ

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...
Reply to this.
Anonymous at 12 Aug, 2008 12:50
I GET THIS ERROR. WHAT DO I HAVE TO CHANGE ON LINE 107 FOR MY WEBSITE WWW.MALLZ.BIZ. PLEASE ADVISE.

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...
Reply to this.
Anonymous at 12 Aug, 2008 01:00
I get another error:

Warning: Division by zero in /home/viart/public_html/sitemap.php on line 119
Reply to this.
Anonymous at 18 Aug, 2008 08:59
Hi

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

Reply to this.
Anish K.S at 24 Oct, 2008 01:44
Binny, I will try this.
Reply to this.
krishna at 24 Oct, 2008 06:25
Hey looks cool man. Though i didn't try this. But, will get back to you soon after a trial run on my websites :-)
Reply to this.
Anonymous at 01 May, 2009 05:00
dear guys,

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
Reply to this.
Chippiewill at 07 May, 2009 02:02
Finnally, a site map script that actually works without hours of config and file placement. Great work!
Reply to this.
Amit at 24 May, 2009 05:15
Hi
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
Reply to this.
Binny V A at 25 May, 2009 11:16
The script cannot find any files to create the sitemap. This script only works on static sites.
Reply to this.
Anonymous at 08 Jun, 2009 04:02
Made a couple changes and the script worked beautiful. Great Job.
Reply to this.
Anonymous at 23 Jun, 2009 08:36
does this script index dynamic pages?
i mean, php or asp
Reply to this.
Anonymous at 24 Jun, 2009 10:54
Please tell us a little more about the need to have sitemap.xml writable and how we can accomplish that. This file did not exit before or after I ran your program so I created an empty file, named it sitemap.xml, changed the attributes to make it writable and still received the Permission denied error. Lost
Reply to this.
Comment

Please dont enter you comments in this form - this is a fake form to confuse spamming bots. The next form is the real one.




Comment




Comment Formating : HTML tags a, strong, em, b, i, code, pre, p and br allowed. Other tags will be shown as code(< will become &lt;). Urls, Line breaks will be auto-formated.
Subscribe to Feed