Home > Backend Development > PHP Tutorial > PHP blog ping service code_PHP tutorial

PHP blog ping service code_PHP tutorial

WBOY
Release: 2016-07-21 15:21:42
Original
920 people have browsed it

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

www.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...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template