Home > Article > Backend Development > huoyingrenzhezhongwenwang PHP blog ping service code
In fact, I have written a class for PHP's ping service code before. However, many friends added me as friends and said that they couldn't understand it. It was written in the form of a class. It may not work if you put it directly into the code and use it directly. , today I will post a ping function that can be used directly. I hope it will be helpful to everyone. One thing that needs to be explained is that the current ping is not as effective as before, because Baidu and gg may have added other indicators, new websites Ping can be successful, but it may not be 100% included.
Copy code The code is as follows:
function postUrl($url, $postvar)
{
$ch = curl_init();
$headers = array(
"POST ".$ url." HTTP/1.0","Content-type: text/xml; charset="gb2312"",
"Accept: text/xml",
"Content-length: ".strlen($postvar)
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ ch , CURLOPT_POSTFIELDS, $postvar);
$res = curl_exec ($ch);
curl_close
($ch);
return $res;
}
$baiduXML = "encoding=" gb2312"?>
< ;value>
$res
= postUrl('http://ping.baidu.com/ ping/RPC2', $baiduXML);
if ( strpos($res, "
{
echo
"PING successful";
}
else
{
echo "PING failed";
}
?>
The above introduces the blog ping service code of huoyingrenzhezhongwenwang PHP, including the content of huoyingrenzhezhongwenwang. I hope it will be helpful to friends who are interested in PHP tutorials.