Thứ Năm, 18 tháng 4, 2019

Ping Multi sitemap bằng php

<?php
set_time_limit(999999);

$sitemaps = array(
"http://xxxxx.com/sitemap.xml",
"http://xxxxx.com/sitemap.xml"
);


// cUrl handler to ping the Sitemap submission URLs for Search Engines…
function Submit($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;
}


function SubmitSiteMap($url) {
  $returnCode = Submit($url);
  if ($returnCode != 200) {
    echo "Error $returnCode: $url <BR/>";
  } else {
    echo "Submitted $returnCode: $url <BR/>";
  }
}


foreach ($sitemaps as $sitemapUrl) {
  $sitemapUrl = htmlentities($sitemapUrl);
  //Google 
  $url = "http://www.google.com/webmasters/sitemaps/ping?sitemap=".$sitemapUrl;
  SubmitSiteMap($url);
 
  //Bing / MSN
  $url = "http://www.bing.com/webmaster/ping.aspx?sitemap=".$sitemapUrl;
  SubmitSiteMap($url);

}

?>

function fakeCurl($strUrl) {

        $oCurl = curl_init($strUrl);
        $lang_parts = explode("_", "en_US");
        curl_setopt_array($oCurl, array(
            CURLOPT_VERBOSE => FALSE,
            CURLOPT_HEADER => TRUE,
            CURLOPT_HTTPHEADER => array(
                'Accept-Language: ' . str_replace("_", "-", "en_US") . ", " . $lang_parts[1] . ';q=0.5'
            ),
            CURLOPT_FRESH_CONNECT => TRUE,
            CURLOPT_RETURNTRANSFER => TRUE,
            CURLOPT_TIMEOUT => 5,
            CURLOPT_CONNECTTIMEOUT => 0,
            CURLOPT_REFERER => 'http://www.google.com',
            CURLOPT_USERAGENT => 'Googlebot/2.1 (+http://www.google.com/bot.html)',
            CURLOPT_FOLLOWLOCATION => FALSE,
            CURLOPT_COOKIEFILE => FALSE
        ));
        return curl_exec($oCurl);
}

Không có nhận xét nào:
Write nhận xét