手动给网站增添ping服务for php
手动给网站添加ping服务for php
转自:http://lwxshow.com/php-setting-ping-manual-google-baidu
?
手动添加ping服务
【1】谷歌的ping服务的php的实现
关于RPC的详细介绍可以移步维基百科,谷歌ping服务的标准:
RPC端点: http://blogsearch.google.com/ping/RPC2
调用方法名: weblogUpdates.extendedPing
参数: (应按照如下所列的相同顺序传送)
站点名
站点URL
需要检查更新的页面URL
相应的RSS、RDF或Atom种子的URL
可选:页面内容的分类名称(或标签)。您可以指定多个值,之间用'|'字符进行分隔。
首先要写一个CURL的函数,来POST谷歌的RPC端点:
$ch = curl_init();
$headers = array(
"POST ".$url." HTTP/1.0″,
"Content-type: text/xml;charset=\"utf-8\"",
"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;
}
主要的curl写好了之后,剩下就是要根据谷歌的XML-RPC标准组装发送的数据了,详细的请求例子可以参考官方案例,点这里。
例如我的代码是这样写的:
END;
$res = postUrl(‘http://blogsearch.google.com/ping/RPC2′, $googleXML);
//下面是返回成功与否的判断(根据谷歌ping的接口说明)
if (strpos($res, "
echo "PING成功";
else
echo "PING失败";
OK,这个就可以简单的实现谷歌的PING服务了。可以根据代码自行修改实现这个功能。
【*2】百度的ping服务的php的实现(这个标题真DT)
百度的ping服务xml代码是跟谷歌不同的,百度总是会有自己的特点:
介绍下百度博客ping服务,百度博客Ping服务的详细介绍,请移步:http://www.baidu.com/search/blogsearch_help.html#n7。
百度的ping服务也是基于XML-RPC标准协议,但是与谷歌ping服务不同的是百度的ping发送的xml格式不同,我们需要使用string节点包裹内容。
例如:
根据上面提到的谷歌接口,我们只要改变一下提交的xml内容即可,当然百度ping服务返回的判断也是跟谷歌的不同,也可以做相应的修改,
下面是php的代码:
EOT;
$res = postUrl(‘http://ping.baidu.com/ping/RPC2′, $baiduXML);
//下面是返回成功与否的判断(根据百度ping的接口说明)
if (strpos($res, "
echo "PING成功";
else
echo "PING失败";
上面的代码就可以实现php的ping服务了。好吧,下面再给各位看管提供一个百度的ping服务代码,没办法谁让他那么独特那?
{
$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 = "
$res = postUrl(‘http://ping.baidu.com/ping/RPC2′, $baiduXML);
if ( strpos($res, "
{
echo "PING成功";
}
else
{
echo "PING失败";
}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Convert basic data types to strings using Java's String.valueOf() function In Java development, when we need to convert basic data types to strings, a common method is to use the valueOf() function of the String class. This function can accept parameters of basic data types and return the corresponding string representation. In this article, we will explore how to use the String.valueOf() function for basic data type conversions and provide some code examples to

Method of converting char array to string: It can be achieved by assignment. Use {char a[]=" abc d\0efg ";string s=a;} syntax to let the char array directly assign a value to string, and execute the code to complete the conversion.

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Hello everyone, today I will share with you the basic knowledge of Java: String. Needless to say the importance of the String class, it can be said to be the most used class in our back-end development, so it is necessary to talk about it.

Replace characters (strings) in a string using Java's String.replace() function In Java, strings are immutable objects, which means that once a string object is created, its value cannot be modified. However, you may encounter situations where you need to replace certain characters or strings in a string. At this time, we can use the replace() method in Java's String class to implement string replacement. The replace() method of String class has two types:

Use Java's String.length() function to get the length of a string. In Java programming, string is a very common data type. We often need to get the length of a string, that is, the number of characters in the string. In Java, we can use the length() function of the String class to get the length of a string. Here is a simple example code: publicclassStringLengthExample{publ

The split method in String uses the split() method of String to split the String according to the incoming characters or strings and return the split array. 1. General usage When using general characters, such as @ or, as separators: Stringaddress="Shanghai@Shanghai City@Minhang District@Wuzhong Road";String[]splitAddr=address.split("@");System .out.println(splitAddr[0]+splitAddr[1]+splitAddr[2]+splitAddr[3
