当前位置: 编程技术>php
php实现百度ping服务的代码
来源: 互联网 发布时间:2014-10-08
本文导语: 首先,ASP实现百度ping服务。 代码示例: 0 Then Response.Write("success") Else Response.Write("failure") End IF Function SendPing(Url) Dim s : s = "" Randomize() Dim r : r = Int(Rnd() * 9999) + 1000 s = s & "" s = s & "" s = s & "weblogUpdates.ping" s = s & ...
首先,ASP实现百度ping服务。
代码示例:
0 Then
Response.Write("success")
Else
Response.Write("failure")
End IF
Function SendPing(Url)
Dim s : s = ""
Randomize()
Dim r : r = Int(Rnd() * 9999) + 1000
s = s & ""
s = s & ""
s = s & "weblogUpdates.ping"
s = s & ""
s = s & "开发网站的一些小技巧"
s = s & "http://hi.baidu.com/subendong/blog"
s = s & "http://hi.baidu.com/subendong/blog/item/6cd9468d243e8c07b21bba5e.html"
s = s & ""
s = s & ""
s = s & ""
Response.Write "
Response.Flush
Dim objPing
Set objPing = Server.CreateObject("MSXML2.ServerXMLHTTP")
objPing.SetTimeOuts 10000, 10000, 10000, 10000
‘第一个数值:解析DNS名字的超时时间10秒
‘第二个数值:建立Winsock连接的超时时间10秒
‘第三个数值:发送数据的超时时间10秒
‘第四个数值:接收response的超时时间10秒
objPing.open "POST", Url & "?r=" & r, False
objPing.setRequestHeader "Content-Type", "text/xml; charset=gb2312″
objPing.send(s)
SendPing = objPing.ResponseBody
Set objPing = Nothing
End Function
‘===============================================
‘函数名:BytesToBstr
‘作用:字符集转换
‘参数:body–内容;Cset–指定的字符集
‘===============================================
Function BytesToBstr(body, Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
%>
Response.Write("success")
Else
Response.Write("failure")
End IF
Function SendPing(Url)
Dim s : s = ""
Randomize()
Dim r : r = Int(Rnd() * 9999) + 1000
s = s & ""
s = s & ""
s = s & "weblogUpdates.ping"
s = s & ""
s = s & "开发网站的一些小技巧"
s = s & "http://hi.baidu.com/subendong/blog"
s = s & "http://hi.baidu.com/subendong/blog/item/6cd9468d243e8c07b21bba5e.html"
s = s & ""
s = s & ""
s = s & ""
Response.Write "
发送Ping到:" & Url & "
"Response.Flush
Dim objPing
Set objPing = Server.CreateObject("MSXML2.ServerXMLHTTP")
objPing.SetTimeOuts 10000, 10000, 10000, 10000
‘第一个数值:解析DNS名字的超时时间10秒
‘第二个数值:建立Winsock连接的超时时间10秒
‘第三个数值:发送数据的超时时间10秒
‘第四个数值:接收response的超时时间10秒
objPing.open "POST", Url & "?r=" & r, False
objPing.setRequestHeader "Content-Type", "text/xml; charset=gb2312″
objPing.send(s)
SendPing = objPing.ResponseBody
Set objPing = Nothing
End Function
‘===============================================
‘函数名:BytesToBstr
‘作用:字符集转换
‘参数:body–内容;Cset–指定的字符集
‘===============================================
Function BytesToBstr(body, Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
%>
2,PHP实现百度ping服务。
代码示例:
weblogUpdates.extendedPing
脚本学堂
http://www.
http://www./a/15222.html
http://www.
";
$res = postUrl(/tech-php/‘http_/ping.baidu.com/ping/RPC2′, $baiduXML/index.html);
if ( strpos($res, "0") )
{
echo "PING成功";
}
else
{
echo "PING失败";
}
?>