Helping ordinary people create extraordinary websites!
   

How to ping Google when sitemap is updated?

Tuesday, 3rd November 2009
by Destro

I have written a PHP script that creates my sitemap.xml file using the information from my mysql database but I am stuck submitting it to google manually each day. I would like to code into my script to ping Google to let it know that the sitemap has been updated after the script runs. How can I ping Google using PHP?



Vader
Hi Destro,
GiJoe fan? :-)

Once your sitemap is created, by whatever means, you can notify Google using any of the following methods:

1. Resubmitting a Sitemap using Google Webmaster Tools

Log into Google Webmaster Tools located at https://www.google.com/webmasters/tools/ and then click on the site that you would like to submit the sitemap for. To the right of the screen under Sitemaps clcik on the link for your sitemap. Once on the Sitemaps page click Resubmit.

2. Resubmitting via sending Google an HTTP request

Request this url www.google.com/webmasters/tools/ping?sitemap=SITEMAP_URL

Your sitemap's url will need to be URL Encoded which can be easily done using the url encode tool here on Developer Tutorials at http://www.developertutorials.com/tools/urlencode-and-urldecode.php

So let's say your sitemap url is www.yoursite.com/sitemap.gz
url encoded it will become http%3A%2F%2Fwww.yoursite.com%2Fsitemap.gz

Put that all together and it should look something like this www.google.com/webmasters/tools/ping?sitemap=http%3A%2F%2Fwww.yoursite.com%2Fsitemap.gz

The request can be submitted via wget, curl or whatever method you choose that will fulfil the requirement.

3. Adding sitemap location to your robots.txt file

Add this to your robots.txt file using your correct url information instead
sitemap: www.example.com/sitemap.xml

Vader.

Sources:

Tuesday, 3rd November 2009
Votes:
32
14

More PHP Help:
» How do I make a PHP5/MySQL login system with admin features?
» What is PHP?
» Convert a string into an array
» How to run PHP on my desktop computer?
» Which script can I use for restoring my MySQL database?
» Code to ask a user to enter data for creating a table using ajax and php
» PHP4 XML Parser when $data is empty..
» Show me the syntax for the months of the year and the number of days in each month output to the screen in php?