首页 > php教程 > PHP源码 > 正文

百度ping接口 百度ping方法

PHP中文网
发布: 2016-05-25 17:00:08
原创
2649人浏览过

跳至

class ping{
	private $title;    //博客名称
	private $hosturl;  //博客首页地址	
	private $arturl;   //新发文章地址
	private $rssurl;   //博客rss地址
	private $baiduXML; //百度XML结构
	private $baiduRPC; //百度XML地址
	
	public function __construct($title,$arturl,$hosturl,$rssurl)
	{
		if(empty($title) || empty($arturl))
			return false;
		$this->title=$title;
		$this->hosturl=$hosturl;
		$this->rssurl=$rssurl;
		$this->arturl=$arturl;
		$this->baiduRPC='http://ping.baidu.com/ping/RPC2';
		
		$this->baiduXML = '';
		$this->baiduXML .='';
		$this->baiduXML .='	weblogUpdates.extendedPing';
		$this->baiduXML .='		';
		$this->baiduXML .='		'.$this->hosturl.'';
		$this->baiduXML .='		'.$this->title.'';
		$this->baiduXML .='		'.$this->arturl.'';
		$this->baiduXML .='		'.$this->rssurl.'';
		$this->baiduXML .='	';
		$this->baiduXML .=''; 
	}
	public function pingbaidu() 
	{ 
		$ch = curl_init();
		$headers=array(
			'User-Agent: request',
			'Host: ping.baidu.com',
			'Content-Type: text/xml',
		);
		curl_setopt($ch, CURLOPT_URL, $this->baiduRPC); 
		curl_setopt($ch, CURLOPT_HEADER, 1);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
		curl_setopt($ch, CURLOPT_POST, 1); 
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
		curl_setopt($ch, CURLOPT_POSTFIELDS, $this->baiduXML); 
		$res = curl_exec ($ch); 
		curl_close ($ch); 
		//return $res;
		return (strpos($res,"0"))?true:false;	
	} 
}
	function get_domain()
	{
		/* 协议 */
		$protocol = 'http://';
		/* 域名或IP地址 */
		if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
			$host = $_SERVER['HTTP_X_FORWARDED_HOST'];
		} elseif (isset($_SERVER['HTTP_HOST'])) {
			$host = $_SERVER['HTTP_HOST'];
		} else {
			/* 端口 */
			if (isset($_SERVER['SERVER_PORT'])) {
				$port = ':' . $_SERVER['SERVER_PORT'];
				if ((':80' == $port & 'http://' == $protocol) || (':443' == $port & 'https://' == $protocol)) {
					$port = '';
				}
			} else {
				$port = '';
			}

			if (isset($_SERVER['SERVER_NAME'])) {
				$host = $_SERVER['SERVER_NAME'] . $port;
			} elseif (isset($_SERVER['SERVER_ADDR'])) {
				$host = $_SERVER['SERVER_ADDR'] . $port;
			}
		}

		return $protocol.$host;
	}
	//$arc = new Ping('网站标题','更新的URL地址','网站域名','rss地址');	
	//$arc = new Ping('你网站的title',get_arcurl($id),get_domain(),'http://www.abc.com/rss.php');
	//echo $arc->pingbaidu();
	//返回结果为0 表示成功。
登录后复制

                   

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号