⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpclient.class.php

📁 一个用PHP编写的
💻 PHP
📖 第 1 页 / 共 3 页
字号:
						}					}										return true;										break;				default:					// not a valid protocol					$this->error	=	'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';					return false;					break;			}					return true;		}	/*======================================================================*\		Function:	fetchlinks		Purpose:	fetch the links from a web page		Input:		$URI	where you are fetching from		Output:		$this->results	an array of the URLs	\*======================================================================*/		function fetchlinks($URI)		{			if ($this->fetch($URI))			{							if($this->lastredirectaddr)					$URI = $this->lastredirectaddr;				if(is_array($this->results))				{					for($x=0;$x<count($this->results);$x++)						$this->results[$x] = $this->_striplinks($this->results[$x]);				}				else					$this->results = $this->_striplinks($this->results);				if($this->expandlinks)					$this->results = $this->_expandlinks($this->results, $URI);				return true;			}			else				return false;		}	/*======================================================================*\		Function:	fetchform		Purpose:	fetch the form elements from a web page		Input:		$URI	where you are fetching from		Output:		$this->results	the resulting html form	\*======================================================================*/		function fetchform($URI)		{			if ($this->fetch($URI))			{							if(is_array($this->results))				{					for($x=0;$x<count($this->results);$x++)						$this->results[$x] = $this->_stripform($this->results[$x]);				}				else					$this->results = $this->_stripform($this->results);				return true;			}			else				return false;		}	/*======================================================================*\		Function:	fetchtext		Purpose:	fetch the text from a web page, stripping the links		Input:		$URI	where you are fetching from		Output:		$this->results	the text from the web page	\*======================================================================*/		function fetchtext($URI)		{			if($this->fetch($URI))			{							if(is_array($this->results))				{					for($x=0;$x<count($this->results);$x++)						$this->results[$x] = $this->_striptext($this->results[$x]);				}				else					$this->results = $this->_striptext($this->results);				return true;			}			else				return false;		}	/*======================================================================*\		Function:	submitlinks		Purpose:	grab links from a form submission		Input:		$URI	where you are submitting from		Output:		$this->results	an array of the links from the post	\*======================================================================*/		function submitlinks($URI, $formvars="", $formfiles="")		{			if($this->submit($URI,$formvars, $formfiles))			{							if($this->lastredirectaddr)					$URI = $this->lastredirectaddr;				if(is_array($this->results))				{					for($x=0;$x<count($this->results);$x++)					{						$this->results[$x] = $this->_striplinks($this->results[$x]);						if($this->expandlinks)							$this->results[$x] = $this->_expandlinks($this->results[$x],$URI);					}				}				else				{					$this->results = $this->_striplinks($this->results);					if($this->expandlinks)						$this->results = $this->_expandlinks($this->results,$URI);				}				return true;			}			else				return false;		}	/*======================================================================*\		Function:	submittext		Purpose:	grab text from a form submission		Input:		$URI	where you are submitting from		Output:		$this->results	the text from the web page	\*======================================================================*/		function submittext($URI, $formvars = "", $formfiles = "")		{			if($this->submit($URI,$formvars, $formfiles))			{							if($this->lastredirectaddr)					$URI = $this->lastredirectaddr;				if(is_array($this->results))				{					for($x=0;$x<count($this->results);$x++)					{						$this->results[$x] = $this->_striptext($this->results[$x]);						if($this->expandlinks)							$this->results[$x] = $this->_expandlinks($this->results[$x],$URI);					}				}				else				{					$this->results = $this->_striptext($this->results);					if($this->expandlinks)						$this->results = $this->_expandlinks($this->results,$URI);				}				return true;			}			else				return false;		}	/*======================================================================*\		Function:	set_submit_multipart		Purpose:	Set the form submission content type to					multipart/form-data	\*======================================================================*/		function set_submit_multipart()		{			$this->_submit_type = "multipart/form-data";		}	/*======================================================================*\		Function:	set_submit_normal		Purpose:	Set the form submission content type to					application/x-www-form-urlencoded	\*======================================================================*/		function set_submit_normal()		{			$this->_submit_type = "application/x-www-form-urlencoded";		}	/*======================================================================*\		Private functions	\*======================================================================*/	/*======================================================================*\		Function:	_striplinks		Purpose:	strip the hyperlinks from an html document		Input:		$document	document to strip.		Output:		$match		an array of the links	\*======================================================================*/		function _striplinks($document)		{				preg_match_all("'<\s*a\s.*?href\s*=\s*			# find <a href=							([\"\'])?					# find single or double quote							(?(1) (.*?)\\1 | ([^\s\>]+))		# if quote found, match up to next matching														# quote, otherwise match up to next space							'isx",$document,$links);			// catenate the non-empty matches from the conditional subpattern			while(list($key,$val) = each($links[2]))			{				if(!empty($val))					$match[] = $val;			}							while(list($key,$val) = each($links[3]))			{				if(!empty($val))					$match[] = $val;			}					// return the links			return $match;		}	/*======================================================================*\		Function:	_stripform		Purpose:	strip the form elements from an html document		Input:		$document	document to strip.		Output:		$match		an array of the links	\*======================================================================*/		function _stripform($document)		{				preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements);			// catenate the matches			$match = implode("\r\n",$elements[0]);			// return the links			return $match;		}	/*======================================================================*\		Function:	_striptext		Purpose:	strip the text from an html document		Input:		$document	document to strip.		Output:		$text		the resulting text	\*======================================================================*/		function _striptext($document)		{			// I didn't use preg eval (//e) since that is only available in PHP 4.0.			// so, list your entities one by one here. I included some of the			// more common ones.			$search = array("'<script[^>]*?>.*?</script>'si",	// strip out javascript							"'<[\/\!]*?[^<>]*?>'si",			// strip out html tags							"'([\r\n])[\s]+'",					// strip out white space							"'&(quot|#34|#034|#x22);'i",		// replace html entities							"'&(amp|#38|#038|#x26);'i",			// added hexadecimal values							"'&(lt|#60|#060|#x3c);'i",							"'&(gt|#62|#062|#x3e);'i",							"'&(nbsp|#160|#xa0);'i",							"'&(iexcl|#161);'i",							"'&(cent|#162);'i",							"'&(pound|#163);'i",							"'&(copy|#169);'i",							"'&(reg|#174);'i",							"'&(deg|#176);'i",							"'&(#39|#039|#x27);'",							"'&(euro|#8364);'i",				// europe							"'&a(uml|UML);'",					// german							"'&o(uml|UML);'",							"'&u(uml|UML);'",							"'&A(uml|UML);'",							"'&O(uml|UML);'",							"'&U(uml|UML);'",							"'&szlig;'i",							);			$replace = array(	"",								"",								"\\1",								"\"",								"&",								"<",								">",								" ",								chr(161),								chr(162),								chr(163),								chr(169),								chr(174),								chr(176),								chr(39),								chr(128),								"盲",								"枚",								"眉",								"脛",								"脰",								"脺",								"脽",							);			$text = preg_replace($search,$replace,$document);			return $text;		}	/*======================================================================*\		Function:	_expandlinks		Purpose:	expand each link into a fully qualified URL		Input:		$links			the links to qualify					$URI			the full URI to get the base from		Output:		$expandedLinks	the expanded links	\*======================================================================*/		function _expandlinks($links,$URI)		{			preg_match("/^[^\?]+/",$URI,$match);			$match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]);			$match = preg_replace("|/$|","",$match);			$match_part = parse_url($match);			$match_root =			$match_part["scheme"]."://".$match_part["host"];			$search = array( 	"|^http://".preg_quote($this->host)."|i",								"|^(\/)|i",								"|^(?!http://)(?!mailto:)|i",								"|/\./|",								"|/[^\/]+/\.\./|"							);			$replace = array(	"",								$match_root."/",								$match."/",								"/",								"/"							);						$expandedLinks = preg_replace($search,$replace,$links);			return $expandedLinks;		}	/*======================================================================*\		Function:	_httprequest		Purpose:	go get the http data from the server		Input:		$url		the url to fetch					$fp			the current open file pointer					$URI		the full URI					$body		body contents to send if any (POST)		Output:			\*======================================================================*/		function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="")		{			$cookie_headers = '';			if($this->passcookies && $this->_redirectaddr)				$this->setcookies();			$URI_PARTS = parse_url($URI);			if(empty($url))				$url = "/";			$headers = $http_method." ".$url." ".$this->_httpversion."\r\n";					if(!empty($this->agent))				$headers .= "User-Agent: ".$this->agent."\r\n";			if(!empty($this->host) && !isset($this->rawheaders['Host'])) {				$headers .= "Host: ".$this->host;				if(!empty($this->port))					$headers .= ":".$this->port;				$headers .= "\r\n";			}			if(!empty($this->accept))				$headers .= "Accept: ".$this->accept."\r\n";			if(!empty($this->referer))				$headers .= "Referer: ".$this->referer."\r\n";			if(!empty($this->cookies))			{							if(!is_array($this->cookies))					$this->cookies = (array)$this->cookies;				reset($this->cookies);				if ( count($this->cookies) > 0 ) {					$cookie_headers .= 'Cookie: ';					foreach ( $this->cookies as $cookieKey => $cookieVal ) {					$cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; ";					}					$headers .= substr($cookie_headers,0,-2) . "\r\n";				} 			}			if(!empty($this->rawheaders))			{				if(!is_array($this->rawheaders))					$this->rawheaders = (array)$this->rawheaders;				while(list($headerKey,$headerVal) = each($this->rawheaders))					$headers .= $headerKey.": ".$headerVal."\r\n";			}			if(!empty($content_type)) {				$headers .= "Content-type: $content_type";				if ($content_type == "multipart/form-data")					$headers .= "; boundary=".$this->_mime_boundary;				$headers .= "\r\n";			}			if(!empty($body))					$headers .= "Content-length: ".strlen($body)."\r\n";			if(!empty($this->user) || !empty($this->pass))					$headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n";			//add proxy auth headers

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -