php ping主机名,php使用百度ping服务代码实例

这段PHP代码实现了向百度站点推送更新内容的功能。通过`postUrl`函数,它构造了XML格式的数据,包括站点URL和文章链接,然后利用cURL发送POST请求到百度的ping服务。如果返回结果中包含'0',则表示推送成功。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 = "<?xml version=\"1.0\" encoding=\"gb2312\"?>

weblogUpdates.extendedPing

愚人渡

https://www.jb51.net

https://www.jb51.net/read.php?tid-96.html

https://www.jb51.net

";

$res = postUrl('http://ping.baidu.com/ping/RPC2', $baiduXML);

if ( strpos($res, "0") )

{

echo "PING成功";

}else{

echo "PING失败";

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值