Home  >  Article  >  Backend Development  >  huoyingrenzhezhongwenwang PHP blog ping service code

huoyingrenzhezhongwenwang PHP blog ping service code

WBOY
WBOYOriginal
2016-07-29 08:47:541524browse

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"?>

weblogUpdates.extendedPing

WEB Development Notes< ; /value>
http://www.jb51.net
< ;value>http://www.jb51.net/001

http://www .jb51.net

";
$res
= postUrl('http://ping.baidu.com/ ping/RPC2', $baiduXML);
if ( strpos($res, "0") )
{
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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn