How to auto submit a Sitemap to Google using PHP

2 Comments

This can be done via a ping service from Google Webmaster Tools

Add the following PHP function 

	function submitSitemap($site)
 
	    {
 
	        $url = 'http://www.google.com/webmasters/sitemaps/ping?sitemap='.htmlentities($site.'/sitemap.xml');
 
	        $response = file_get_contents($url);
 
	        
 
	        if($response){
 
	          echo $response;
 
	        }else{
 
	          echo "Failed to submit sitemap";
 
	        }
 
	    }

Now you need to call the above function as example below to submit your sitemap to Google.

submitSitemap('http://www.mysite.com'); //Replace http://www.mysite.com with your website

Once the sitemap has been submitted the following message will be returned

Sitemap Notification Received

Your Sitemap has been successfully added to our list of Sitemaps to crawl. If this is the first time you are notifying Google about this Sitemap, please add it via http://www.google.com/webmasters/tools/ so you can track its status. Please note that we do not add all submitted URLs to our index, and we cannot make any predictions or guarantees about when or if they will appear.

Image Credits: Photo by Isis França on Unsplash.

Last Updated On March 22, 2018

Related Articles

No results found

2
Leave a Reply

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
George Fisherjohn Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
john
Guest
john

doesnt work or add it to your google webmaster tools list of sitemaps

George Fisher
Guest
George Fisher

works great. thanks

Menu
Copy link