📄 http.php
字号:
$arguments["HostName"]=$parameters["host"]; $arguments["Headers"]=array("Host"=>$parameters["host"].(IsSet($parameters["port"]) ? ":".$parameters["port"] : "")); if(IsSet($parameters["user"])) $arguments["AuthUser"]=UrlDecode($parameters["user"]); if(IsSet($parameters["pass"])) $arguments["AuthPassword"]=UrlDecode($parameters["pass"]); if(IsSet($parameters["port"])) { if(strcmp($parameters["port"],strval(intval($parameters["port"])))) return($this->SetError("it was not specified a valid connection host argument")); $arguments["HostPort"]=intval($parameters["port"]); } else $arguments["HostPort"]=0; $arguments["RequestURI"]=(IsSet($parameters["path"]) ? $parameters["path"] : "/").(IsSet($parameters["query"]) ? "?".$parameters["query"] : ""); if(strlen($this->user_agent)) $arguments["Headers"]["User-Agent"]=$this->user_agent; return(""); } Function Open($arguments) { if(strlen($this->error)) return($this->error); if($this->state!="Disconnected") return("1 already connected"); if(IsSet($arguments["HostName"])) $this->host_name=$arguments["HostName"]; if(IsSet($arguments["HostPort"])) $this->host_port=$arguments["HostPort"]; if(IsSet($arguments["ProxyHostName"])) $this->proxy_host_name=$arguments["ProxyHostName"]; if(IsSet($arguments["ProxyHostPort"])) $this->proxy_host_port=$arguments["ProxyHostPort"]; if(IsSet($arguments["Protocol"])) $this->protocol=$arguments["Protocol"]; switch(strtolower($this->protocol)) { case "http": $default_port=80; break; case "https": $default_port=443; break; default: return($this->SetError("2 it was not specified a valid connection protocol")); } if(strlen($this->proxy_host_name)==0) { if(strlen($this->host_name)==0) return($this->SetError("2 it was not specified a valid hostname")); $host_name=$this->host_name; $host_port=($this->host_port ? $this->host_port : $default_port); } else { $host_name=$this->proxy_host_name; $host_port=$this->proxy_host_port; } $ssl=(strtolower($this->protocol)=="https" && strlen($this->proxy_host_name)==0); $this->use_curl=($ssl && function_exists("curl_init")); if($this->use_curl) { $error=(($this->connection=curl_init($this->protocol."://".$this->host_name.($host_port==$default_port ? "" : ":".strval($host_port))."/")) ? "" : "Could not initialize a CURL session"); if(strlen($error)==0) { if(IsSet($arguments["SSLCertificateFile"])) curl_setopt($this->connection,CURLOPT_SSLCERT,$arguments["SSLCertificateFile"]); if(IsSet($arguments["SSLCertificatePassword"])) curl_setopt($this->connection,CURLOPT_SSLCERTPASSWD,$arguments["SSLCertificatePassword"]); } } else { $error=""; if(strlen($this->proxy_host_name) && IsSet($arguments["SSLCertificateFile"])) $error="establishing SSL connections using certificates via non-SSL proxies is not supported"; else { if($ssl) { if(IsSet($arguments["SSLCertificateFile"])) $error="establishing SSL connections using certificates is only supported when the cURL extension is enabled"; else { $version=explode(".",function_exists("phpversion") ? phpversion() : "3.0.7"); $php_version=intval($version[0])*1000000+intval($version[1])*1000+intval($version[2]); if($php_version<4003000) $error="establishing SSL connections requires at least PHP version 4.3.0 or having the cURL extension enabled"; elseif(!function_exists("extension_loaded") || !extension_loaded("openssl")) $error="establishing SSL connections requires the OpenSSL extension enabled"; } } if(strlen($error)==0) $error=$this->Connect($host_name,$host_port,$ssl); } } if(strlen($error)) return($this->SetError($error)); $this->state="Connected"; return(""); } Function Close() { if($this->state=="Disconnected") return("1 already disconnected"); $error=$this->Disconnect(); if(strlen($error)==0) $this->state="Disconnected"; return($error); } Function PickCookies(&$cookies,$secure) { if(IsSet($this->cookies[$secure])) { $now=gmdate("Y-m-d H-i-s"); for($domain=0,Reset($this->cookies[$secure]);$domain<count($this->cookies[$secure]);Next($this->cookies[$secure]),$domain++) { $domain_pattern=Key($this->cookies[$secure]); $match=strlen($this->request_host)-strlen($domain_pattern); if($match>=0 && !strcmp($domain_pattern,substr($this->request_host,$match)) && ($match==0 || $domain_pattern[0]=="." || $this->request_host[$match-1]==".")) { for(Reset($this->cookies[$secure][$domain_pattern]),$path_part=0;$path_part<count($this->cookies[$secure][$domain_pattern]);Next($this->cookies[$secure][$domain_pattern]),$path_part++) { $path=Key($this->cookies[$secure][$domain_pattern]); if(strlen($this->request_uri)>=strlen($path) && substr($this->request_uri,0,strlen($path))==$path) { for(Reset($this->cookies[$secure][$domain_pattern][$path]),$cookie=0;$cookie<count($this->cookies[$secure][$domain_pattern][$path]);Next($this->cookies[$secure][$domain_pattern][$path]),$cookie++) { $cookie_name=Key($this->cookies[$secure][$domain_pattern][$path]); $expires=$this->cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"]; if($expires=="" || strcmp($now,$expires)<0) $cookies[$cookie_name]=$this->cookies[$secure][$domain_pattern][$path][$cookie_name]; } } } } } } } Function GetFileDefinition(&$file,&$definition) { $name=""; if(IsSet($file["FileName"])) $name=basename($file["FileName"]); if(IsSet($file["Name"])) $name=$file["Name"]; if(strlen($name)==0) return("it was not specified the file part name"); if(IsSet($file["Content-Type"])) { $content_type=$file["Content-Type"]; $type=$this->Tokenize(strtolower($content_type),"/"); $sub_type=$this->Tokenize(""); switch($type) { case "text": case "image": case "audio": case "video": case "application": case "message": break; case "automatic": switch($sub_type) { case "name": switch(GetType($dot=strrpos($name,"."))=="integer" ? strtolower(substr($name,$dot)) : "") { case ".xls": $content_type="application/excel"; break; case ".hqx": $content_type="application/macbinhex40"; break; case ".doc": case ".dot": case ".wrd": $content_type="application/msword"; break; case ".pdf": $content_type="application/pdf"; break; case ".pgp": $content_type="application/pgp"; break; case ".ps": case ".eps": case ".ai": $content_type="application/postscript"; break; case ".ppt": $content_type="application/powerpoint"; break; case ".rtf": $content_type="application/rtf"; break; case ".tgz": case ".gtar": $content_type="application/x-gtar"; break; case ".gz": $content_type="application/x-gzip"; break; case ".php": case ".php3": $content_type="application/x-httpd-php"; break; case ".js": $content_type="application/x-javascript"; break; case ".ppd": case ".psd": $content_type="application/x-photoshop"; break; case ".swf": case ".swc": case ".rf": $content_type="application/x-shockwave-flash"; break; case ".tar": $content_type="application/x-tar"; break; case ".zip": $content_type="application/zip"; break; case ".mid": case ".midi": case ".kar": $content_type="audio/midi"; break; case ".mp2": case ".mp3": case ".mpga": $content_type="audio/mpeg"; break; case ".ra": $content_type="audio/x-realaudio"; break; case ".wav": $content_type="audio/wav"; break; case ".bmp": $content_type="image/bitmap"; break; case ".gif": $content_type="image/gif"; break; case ".iff": $content_type="image/iff"; break; case ".jb2": $content_type="image/jb2"; break; case ".jpg": case ".jpe": case ".jpeg": $content_type="image/jpeg"; break; case ".jpx": $content_type="image/jpx"; break; case ".png": $content_type="image/png"; break; case ".tif": case ".tiff": $content_type="image/tiff"; break; case ".wbmp": $content_type="image/vnd.wap.wbmp"; break; case ".xbm": $content_type="image/xbm"; break; case ".css": $content_type="text/css"; break; case ".txt": $content_type="text/plain"; break; case ".htm": case ".html": $content_type="text/html"; break; case ".xml": $content_type="text/xml"; break; case ".mpg": case ".mpe": case ".mpeg": $content_type="video/mpeg"; break; case ".qt": case ".mov": $content_type="video/quicktime"; break; case ".avi": $content_type="video/x-ms-video"; break; case ".eml": $content_type="message/rfc822"; break; default: $content_type="application/octet-stream"; break; } break; default: return($content_type." is not a supported automatic content type detection method"); } break; default: break; return($content_type." is not a supported file content type"); } } else $content_type="application/octet-stream"; $definition=array( "Content-Type"=>$content_type, "NAME"=>$name ); if(IsSet($file["FileName"])) { if(GetType($length=@filesize($file["FileName"]))!="integer") { $error="it was not possible to determine the length of the file ".$file["FileName"]; if(IsSet($php_errormsg) && strlen($php_errormsg)) $error.=": ".$php_errormsg; if(!file_exists($file["FileName"])) $error="it was not possible to access the file ".$file["FileName"]; return($error); } $definition["FILENAME"]=$file["FileName"]; $definition["Content-Length"]=$length; } elseif(IsSet($file["Data"])) $definition["Content-Length"]=strlen($definition["DATA"]=$file["Data"]); else return("it was not specified a valid file name"); return(""); } Function SendRequest($arguments) { if(strlen($this->error)) return($this->error); switch($this->state) { case "Disconnected": return($this->SetError("1 connection was not yet established")); case "Connected": break; default: return($this->SetError("2 can not send request in the current connection state")); } if(IsSet($arguments["RequestMethod"])) $this->request_method=$arguments["RequestMethod"]; if(IsSet($arguments["User-Agent"])) $this->user_agent=$arguments["User-Agent"]; if(strlen($this->request_method)==0) return($this->SetError("3 it was not specified a valid request method")); if(IsSet($arguments["RequestURI"])) $this->request_uri=$arguments["RequestURI"]; if(strlen($this->request_uri)==0 || substr($this->request_uri,0,1)!="/") return($this->SetError("4 it was not specified a valid request URI")); $this->request_body=""; $this->request_headers=(IsSet($arguments["Headers"]) ? $arguments["Headers"] : array()); $body_length=0; $this->request_body=""; if($this->request_method=="POST") { if(IsSet($arguments["PostFiles"]) || ($this->force_multipart_form_post && IsSet($arguments["PostValues"]))) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -