Tags: google,php,yahoo,ask

Sort by: Date / Title /

  1. 1 year ago by spirit and saved by 2 others
    Si vous possédez un sitemap dynamique, vous pouvez notifier google, yahoo et ask de sa mise à jour. Renvoie HTTP/1.1 200 OK si tout s'est bien passé. Vous mettez dans un crontab ce script ainsi que la génération du sitemap et c'est gagné (0 0 * * * et 0 12 * * * pour respectivement minuit et midi tous les jours).
    1. $sitemapUrl = 'http://www.monsite.com/sitemap.xml';
    2.  
    3. //google
    4. $google_return = pingSitemap($sitemapUrl, 'http://www.google.com/webmasters/sitemaps/ping?sitemap=');
    5. //ask
    6. $ask_return = pingSitemap($sitemapUrl, 'http://submissions.ask.com/ping?sitemap=');
    7. //yahoo
    8. $yahoo_return = pingSitemap($sitemapUrl, 'http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=');
    9.  
    10. echo $google_return;
    11. echo $ask_return;
    12. echo $yahoo_return;
    13.  
    14. function pingSitemap ($sitemapUrl, $notifyUrl) {
    15.  
    16.     $fileName = $notifyUrl . urlencode($sitemapUrl);
    17.  
    18.     $url = parse_url($fileName);
    19.     if (!isset($url["port"])) $url["port"] = 80;
    20.     if (!isset($url["path"])) $url["path"] = "/";
    21.  
    22.     $fp = @fsockopen($url["host"],
    23.                      $url["port"],
    24.                      &$errno, &$errstr, 30);
    25.  
    26.     if ($fp) {
    27.         $head = "";
    28.         $httpRequest = "HEAD ". $url["path"] ."?"
    29.                      .$url["query"] ." HTTP/1.1\r\n"
    30.                      ."Host: ". $url["host"] ."\r\n"
    31.                      ."Connection: close\r\n\r\n";
    32.  
    33.         fputs($fp, $httpRequest);
    34.         while(!feof($fp)) $head .= fgets($fp, 1024);
    35.         fclose($fp);
    36.  
    37.         return $head;
    38.  
    39.     }
    40.  
    41. return "ERROR";
    42.  
    43. }

First / Previous / Next / Last / Page 1 of 1 (1 posteets)