In fact, I have written a class for the PHP 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
< value>WEB Development Notes
http://www.jb51.net string>
http://www.jb51.net/001 param>
http://www.jb51.net
";
$res
= postUrl('http://ping.baidu.com/ping/RPC2', $baiduXML);
if ( strpos($res, "
0") )
{
echo
"PING successful";
}
else
{
echo "PING failed";
}
?>
http://www.bkjia.com/PHPjc/324868.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324868.htmlTechArticlePHP’s ping service code I have actually written a class before, but many friends added me as friends and said , I don’t quite understand it. It’s written in the form of a class. Maybe if I put it directly into the code...