{"id":232689,"date":"2023-01-26T10:49:00","date_gmt":"2023-01-26T07:49:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232689"},"modified":"2023-02-05T12:53:21","modified_gmt":"2023-02-05T09:53:21","slug":"come-inviare-automaticamente-le-sitemap-utilizzando-php","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/it\/come-inviare-automaticamente-le-sitemap-utilizzando-php\/","title":{"rendered":"Come inviare automaticamente le Sitemap utilizzando PHP?"},"content":{"rendered":"<p>Le Sitemap sono utili ai robot di ricerca per conoscere meglio le strutture del tuo sito. Sono particolarmente utili se il tuo sito contiene diverse centinaia di pagine. Puoi accedere a <a href=\"https:\/\/wordpress.mediadoma.com\/it\/sostituisci-la-casella-di-ricerca-integrata-in-wordpress-con-google-personalizza-la-ricerca\/\" title=\"Google Webmaster\">Google Webmaster<\/a> o Bing Master (o altri strumenti simili per siti Web) per inviare manualmente le mappe del sito. Se hai molte mappe del sito (o molti siti Web), questo sar\u00e0 un mal di testa. Che ne dici di inviare automaticamente le mappe del sito (per far sapere ai <a href=\"https:\/\/wordpress.mediadoma.com\/it\/come-aggiungere-il-motore-di-ricerca-di-google-al-blog-di-wordpress-widget-codice-html-semplice\/\" title=\"motori di ricerca\">motori di ricerca<\/a> che hai aggiornamenti)?<\/p>\n<p>Mappa del sito<\/p>\n<p>Per prima cosa definisci l&#8217;array di URL delle mappe del sito usando <a href=\"https:\/\/helloacm.com\/php-script-to-execute-mysql-statements-in-a-text-file\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">PHP<\/a> :<\/p>\n<pre><code>$sitemaps = array(\n\u00a0 \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"https:\/\/helloacm.com\/sitemap.xml\" rel=\"nofollow\"&gt;&lt;span&gt;https&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;helloacm&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;sitemap&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;xml&lt;\/span&gt;&lt;\/a&gt;\",\n\u00a0 \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"https:\/\/codingforspeed.com\/sitemap.xml\" rel=\"nofollow\"&gt;&lt;span&gt;https&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;codingforspeed&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;sitemap&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;xml&lt;\/span&gt;&lt;\/a&gt;\",\n\u00a0 \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"https:\/\/codingforspeed.com\/forum\/sitemap.php\" rel=\"nofollow\"&gt;&lt;span&gt;https&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;codingforspeed&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;forum&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;sitemap&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;php&lt;\/span&gt;&lt;\/a&gt;\",\n\u00a0 \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"https:\/\/uploadbeta.com\/sitemap.xml\" rel=\"nofollow\"&gt;&lt;span&gt;https&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;uploadbeta&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;sitemap&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;xml&lt;\/span&gt;&lt;\/a&gt;\",\n\u00a0 \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"https:\/\/rot47.net\/sitemap.xml\" rel=\"nofollow\"&gt;&lt;span&gt;https&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;rot47&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;net&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;sitemap&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;xml&lt;\/span&gt;&lt;\/a&gt;\",\n\u00a0 \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"https:\/\/justyy.com\/sitemap.xml\" rel=\"nofollow\"&gt;&lt;span&gt;https&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;justyy&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;sitemap&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;xml&lt;\/span&gt;&lt;\/a&gt;\",\n\u00a0 \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"https:\/\/steakovercooked.com\/sitemap.xml\" rel=\"nofollow\"&gt;&lt;span&gt;https&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;steakovercooked&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;sitemap&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;xml&lt;\/span&gt;&lt;\/a&gt;\",\n\u00a0 \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"https:\/\/steakovercooked.com\/wedding\/sitemap.xml\" rel=\"nofollow\"&gt;&lt;span&gt;https&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;steakovercooked&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;wedding&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;sitemap&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;xml&lt;\/span&gt;&lt;\/a&gt;\"\n);<\/code><\/pre>\n<p>Quindi definisci due funzioni:<\/p>\n<pre><code>\/\/ cUrl handler to ping the Sitemap submission URLs for Search Engines\u2026\nfunction Submit($url){\n\u00a0 $ch = curl_init($url);\n\u00a0 curl_setopt($ch, CURLOPT_HEADER, 0);\n\u00a0 curl_exec($ch);\n\u00a0 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);\n\u00a0 curl_close($ch);\n\u00a0 return $httpCode;\n}\n\u00a0\nfunction SubmitSiteMap($url) {\n\u00a0 $returnCode = Submit($url);\n\u00a0 if ($returnCode != 200) {\n\u00a0 \u00a0 echo \"Error $returnCode: $url &lt;BR\/&gt;\";\n\u00a0 } else {\n\u00a0 \u00a0 echo \"Submitted $returnCode: $url &lt;BR\/&gt;\";\n\u00a0 }\n}<\/code><\/pre>\n<p>Quindi tutto ci\u00f2 che devi fare \u00e8 iterare tutte le <a href=\"https:\/\/helloacm.com\/creating-sitemap-generator-for-phpbb3-1-using-php\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">mappe<\/a> del sito e inviarle ai diversi motori di ricerca:<\/p>\n<pre><code>foreach ($sitemaps as $sitemapUrl) {\n\u00a0 $sitemapUrl = htmlentities($sitemapUrl);\n\u00a0\n\u00a0 \/\/Google \u00a0\n\u00a0 $url = \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"http:\/\/www.google.com\/webmasters\/sitemaps\/ping?sitemap=\".$sitemapUrl\" rel=\"nofollow\"&gt;&lt;span&gt;http&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;www&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;google&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;webmasters&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;sitemaps&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;ping&lt;\/span&gt;&lt;span&gt;?&lt;\/span&gt;&lt;span&gt;sitemap&lt;\/span&gt;&lt;span&gt;=\".$&lt;\/span&gt;&lt;span&gt;sitemapUrl&lt;\/span&gt;&lt;\/a&gt;;\n\u00a0 SubmitSiteMap($url);\n\u00a0 \n\u00a0 \/\/Bing \/ MSN\n\u00a0 $url = \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"http:\/\/www.bing.com\/webmaster\/ping.aspx?siteMap=\".$sitemapUrl\" rel=\"nofollow\"&gt;&lt;span&gt;http&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;www&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;bing&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;webmaster&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;ping&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;aspx&lt;\/span&gt;&lt;span&gt;?&lt;\/span&gt;&lt;span&gt;siteMap&lt;\/span&gt;&lt;span&gt;=\".$&lt;\/span&gt;&lt;span&gt;sitemapUrl&lt;\/span&gt;&lt;\/a&gt;;\n\u00a0 SubmitSiteMap($url);\n\u00a0 \n\u00a0 \/\/ Live\n\u00a0 $url = \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"http:\/\/webmaster.live.com\/ping.aspx?siteMap=\".$sitemapUrl\" rel=\"nofollow\"&gt;&lt;span&gt;http&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;webmaster&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;live&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;ping&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;aspx&lt;\/span&gt;&lt;span&gt;?&lt;\/span&gt;&lt;span&gt;siteMap&lt;\/span&gt;&lt;span&gt;=\".$&lt;\/span&gt;&lt;span&gt;sitemapUrl&lt;\/span&gt;&lt;\/a&gt;;\n\u00a0 SubmitSiteMap($url);\n\u00a0 \n\u00a0 \/\/ moreover\n\u00a0 $url = \"&lt;a class=\"vglnk\" target=\"_blank\" href=\"http:\/\/api.moreover.com\/ping?sitemap=\".$sitemapUrl\" rel=\"nofollow\"&gt;&lt;span&gt;http&lt;\/span&gt;&lt;span&gt;:\/\/&lt;\/span&gt;&lt;span&gt;api&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;moreover&lt;\/span&gt;&lt;span&gt;.&lt;\/span&gt;&lt;span&gt;com&lt;\/span&gt;&lt;span&gt;\/&lt;\/span&gt;&lt;span&gt;ping&lt;\/span&gt;&lt;span&gt;?&lt;\/span&gt;&lt;span&gt;sitemap&lt;\/span&gt;&lt;span&gt;=\".$&lt;\/span&gt;&lt;span&gt;sitemapUrl&lt;\/span&gt;&lt;\/a&gt;;\n\u00a0 SubmitSiteMap($url);\n}<\/code><\/pre>\n<p>Aggiungi quanto segue all&#8217;inizio, che non fissa un limite di tempo, se vuoi aggiungere questo lavoro nel <a href=\"https:\/\/helloacm.com\/php-script-to-test-crontab\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">crontab<\/a>.<\/p>\n<p>Infine, puoi aggiungerlo a <a href=\"https:\/\/helloacm.com\/how-to-get-a-email-when-system-load-average-is-high-crontab\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">crontab -e<\/a><\/p>\n<pre><code>@daily php submit_sitemap.php<\/code><\/pre>\n<p>Inoltre, la funzione Invia pu\u00f2 essere semplificata utilizzando <a href=\"https:\/\/helloacm.com\/file_put_contents-substitute-in-php\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">file_get_contents<\/a> se non vuoi sapere se l&#8217;invio ha esito positivo (nessun codice di ritorno).<\/p>\n<pre><code>function Submit($url) {\n\u00a0 file_get_contents($url);\n}<\/code><\/pre>\n<p>Il codice sorgente completo \u00e8 disponibile su <a href=\"https:\/\/helloacm.com\/github\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">github<\/a>: <a href=\"https:\/\/github.com\/DoctorLai\/Sitemaps_PHP\/blob\/master\/submit_sitemaps.php\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">submit_sitemaps.php<\/a><\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">Fonte di registrazione:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Come inviare automaticamente le Sitemap utilizzando PHP?<\/p>\n","protected":false},"author":1,"featured_media":223852,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[896,996,804,1007,720,844,865],"tags":[1168],"class_list":["post-232689","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codice","category-marketing-dei-contenuti","category-php-6","category-seo-7","category-sviluppatore","category-tutorial","category-wordpress-6","tag-affiai-it"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts\/232689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/comments?post=232689"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts\/232689\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/media\/223852"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/media?parent=232689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/categories?post=232689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/tags?post=232689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}