Script to automatically submit your sitemap to Google, Bing, Yahoo, Ask, etc…

The other day I made a post with example code to create a Google based Sitemap.  In today’s post I am going to write a quick little function to show you how to submit your Sitemap to engines such as Google, Bing / MSN, Ask, etc.

Each of these major search engines has a Sitemap submission service.  Both Google and Bing have great webmaster tools where you can get information on your submitted sitemaps, along with general indexing stats.  I highly recommend signing up for these services so that you can track and monitor your sitemap submissions.  You can also be alerted to errors with your sitemap as well.

In this example we are going to use a simple cUrl process in PHP to ping the Google, Bing/MSN and Ask search Engine Sitemap submission urls.  Yahoo is not included in the list because back in 2012 they shut down the submission service and have been utilizing MSN’s services.

The only thing you need to do is set the full absolute path to your Sitemap in the variable below.  I set it to my sample file at : http://www.benhalbenhall.com/sitemap.xml

======

/*
* Sitemap Submitter
* Use this script to submit your site maps automatically to Google, Bing.MSN and Ask
* Trigger this script on a schedule of your choosing or after your site map gets updated.
*/

//Set this to be your site map URL
$sitemapUrl = "http://www.5vote.com/sitemap.xml";

// cUrl handler to ping the Sitemap submission URLs for Search Engines…
function myCurl($url){
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_exec($ch);
  $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);
  return $httpCode;
}

//Google
$url = "http://www.google.com/webmasters/sitemaps/ping?sitemap=".$sitemapUrl;
$returnCode = myCurl($url);
echo "<p>Google Sitemaps has been pinged (return code: $returnCode).</p>";

//Bing / MSN
$url = "http://www.bing.com/webmaster/ping.aspx?siteMap=".$sitemapUrl;
$returnCode = myCurl($url);
echo "<p>Bing / MSN Sitemaps has been pinged (return code: $returnCode).</p>";

//ASK
$url = "http://submissions.ask.com/ping?sitemap=".$sitemapUrl;
$returnCode = myCurl($url);
echo "<p>ASK.com Sitemaps has been pinged (return code: $returnCode).</p>";

====

I hope that was helpful!

Comments

comments

Posted in and tagged , , , , .