Home php教程 PHP源码 百度ping接口 百度ping方法

百度ping接口 百度ping方法

May 25, 2016 pm 05:00 PM

跳至

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 表示成功。
Copy after login

                   

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)