Skip to content

Commit 58c241b

Browse files
authored
update i18n documentation
1 parent 2af0185 commit 58c241b

File tree

1 file changed

+53
-41
lines changed

1 file changed

+53
-41
lines changed

src/php_curl/curl.php

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* Curl Class
44
*
55
* @author http://weibo.com/yakeing
6-
* @version 2.1
6+
* @version 2.2
77
* Prompt: CertUrl The server may not contain root / chain SSL certificates, causing authentication errors
8-
* 注意: CertUrl 服务器可能不包含根/链SSL证书,导致身份验证错误
8+
* 注意: 服务器证书可能不包含根/链SSL证书,导致身份验证错误
99
* Prompt: When you open the {HeadOut} option, GET/POST returns only false
1010
* 注意:当您打开{HeadOut}选项时,GET / POST仅返回false
1111
*
@@ -19,32 +19,33 @@ class curl{
1919
public $Body = '';
2020
public $HttpCode = 0;
2121
public $HttpError = '';
22-
public $HttpUrl = ''; //有效发送地址(最后一个)
22+
public $HttpUrl = ''; //最后一个有效发送地址
2323
public $HeadersOut = ''; //发送的头部
2424
public $HttpCookie = array(); //返回 Cookie
2525

26-
public $Cookie = array(); //设置Cookie
26+
public $CurlOpt = array(); //自定义 Curl 选项
27+
public $Cookie = array(); //设置 Cookie
2728
public $Timeout = 5; //运行时间
2829
public $Referer = ''; //伪装来源
29-
public $CertUrl = ''; //HTTPS地址SSL证书
30+
public $CertUrl = ''; //HTTPS地址SSL证书路径
3031
public $HeadersOn = false; //输出头部信息
31-
public $HeaderFunction = false; //回调函数(头部)
32+
public $HeaderFunction = false; //回调函数(返回头部)
3233
public $HeadOut = false; //回调函数(只输出头部)
33-
public $LocationQuantity = 0; //自动重定向次数(301/302)
34+
public $LocationQuantity = 0; //自动重定向次数(HTTP 301/302)
3435
public $Encoding = 'deflate, gzip'; //压缩 1.identity、2.deflate, gzip
35-
public $UserAgent = 'Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)';
36+
public $UserAgent = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html )';
3637

3738
//Constructor
3839
public function __construct(){
3940
if(function_exists('curl')){
40-
throw new Exception('php需要Curl函数支持或被关闭');
41+
throw new Exception('Curl not defined');
4142
}
4243
} //END __construct
4344

4445
//Get Network Resources
4546
public function Get($Url, $Header = array()){
4647
$Options = $this->Options($Url, $Header);
47-
//$Options[CURLOPT_HTTPGET] = true; //默认
48+
//$Options[CURLOPT_HTTPGET] = true; //default setting
4849
return $this->Http($Options);
4950
} //NDE Get
5051

@@ -59,52 +60,63 @@ public function Post($Url, $Vars, $Header = array()){
5960
//Curl Options
6061
private function Options($Url, $Header){
6162
$Options = array(
62-
CURLOPT_URL => $Url, //URL 地址
63-
CURLOPT_USERAGENT => $this->UserAgent, //客户UA标示
64-
CURLOPT_TIMEOUT => $this->Timeout, //运行秒
65-
CURLOPT_CONNECTTIMEOUT => $this->Timeout, //连接秒
66-
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, //http 1.1版本
67-
CURLOPT_RETURNTRANSFER => true, //返回文件流
63+
CURLOPT_URL => $Url, //Destination address(URL)
64+
CURLOPT_USERAGENT => $this->UserAgent, //Customer UA mark
65+
CURLOPT_TIMEOUT => $this->Timeout, //Running time (sec)
66+
CURLOPT_CONNECTTIMEOUT => $this->Timeout, //Connection time (sec)
67+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, //http 1.1 Edition
68+
CURLOPT_RETURNTRANSFER => true, //Return file stream
6869
//CURLOPT_COOKIESESSION => true, //session cookie
69-
CURLINFO_HEADER_OUT => true //追踪句柄的请求
70+
CURLINFO_HEADER_OUT => true //Request for trace handle
7071
);
71-
//不输出Body(无法接收cookie)
72+
//Closing Body will not be able to receive cookie information
7273
//$Options[CURLOPT_NOBODY] = true;
73-
if(!empty($Header)){//设置头部信息
74+
if(!empty($Header)){//Set header information
7475
$Options[CURLOPT_HTTPHEADER] = $Header;
7576
}
76-
if(strrpos($Url, 'https://') === 0){//https模式
77+
if(strrpos($Url, 'https://') === 0){//https mode
7778
if(empty($this->CertUrl)){
78-
$Options[CURLOPT_SSL_VERIFYPEER] = false;//https安全
79-
$Options[CURLOPT_SSL_VERIFYHOST] = false;//证书检查
79+
$Options[CURLOPT_SSL_VERIFYPEER] = false;//https peer’s certificate OFF
80+
$Options[CURLOPT_SSL_VERIFYHOST] = false;//No inspection certificate
8081
}else{
81-
$Options[CURLOPT_SSL_VERIFYPEER] = true;//https安全
82-
$Options[CURLOPT_SSL_VERIFYHOST] = 2;//严格认证
83-
$Options[CURLOPT_CAINFO] = $this->CertUrl;//证书地址
82+
$Options[CURLOPT_SSL_VERIFYPEER] = true;//Validation of peer’s certificate
83+
$Options[CURLOPT_SSL_VERIFYHOST] = 2;//Does the Certificate Common Name match the hostname (Strict certification)
84+
$Options[CURLOPT_CAINFO] = $this->CertUrl;//Certificate address
8485
}
8586
}
86-
if(is_int($this->LocationQuantity) && $this->LocationQuantity > 0){//递归 自动重定向次数(301/302)
87-
$Options[CURLOPT_FOLLOWLOCATION] = true;//重定向
88-
$Options[CURLOPT_AUTOREFERER] = true;//重定向自动设置Referer:信息
89-
$Options[CURLOPT_MAXREDIRS] = $this->LocationQuantity; //重定向次数
87+
if(is_int($this->LocationQuantity) && $this->LocationQuantity > 0){//redirection (HTTP 301/302)
88+
$Options[CURLOPT_FOLLOWLOCATION] = true;//Open redirection
89+
$Options[CURLOPT_AUTOREFERER] = true;//Redirection automatically sets Referer information
90+
$Options[CURLOPT_MAXREDIRS] = $this->LocationQuantity; //Redirection times
9091
}
91-
if(!empty($this->Cookie)){//Cookie信息
92-
$Options[CURLOPT_COOKIE] = $this->Cookie;
92+
if(!empty($this->Cookie)){//Cookie information
93+
if(is_array($this->Cookie)){
94+
$cookie = '';
95+
foreach ($this->Cookie as $key => $value) {
96+
$cookie .= $key.'='.$value.';';
97+
}
98+
}else{ //is_string($this->Cookie)
99+
$cookie = $this->Cookie;
100+
}
101+
$Options[CURLOPT_COOKIE] = $cookie;
93102
}
94-
if(!empty($this->Referer)){//伪装来源
103+
if(!empty($this->Referer)){//Camouflage source
95104
$Options[CURLOPT_REFERER] = $this->Referer;
96105
}
97-
if(!empty($this->Encoding)){//压缩
106+
if(!empty($this->Encoding)){//compress
98107
$Options[CURLOPT_ENCODING] = $this->Encoding;
99108
}
100-
if($this->HeadersOn === true){//返回头部
109+
if($this->HeadersOn === true){//Back header
101110
$Options[CURLOPT_HEADER] = true;
102111
}
103-
if($this->HeaderFunction === true){//回调函数(获取头部)
112+
if($this->HeaderFunction === true){//callback (Get header)
104113
$Options[CURLOPT_HEADERFUNCTION] = array($this, 'HeaderFunction');
105114
}
115+
if(count($this->CurlOpt)>0){//Add or change Curl Options
116+
$Options = array_merge($Options, $this->CurlOpt);
117+
}
106118
return $Options;
107-
}
119+
} //END Options
108120

109121
// Header Function
110122
private function HeaderFunction($thising, $header){
@@ -131,15 +143,15 @@ private function Http($options){
131143
$ch = curl_init();
132144
curl_setopt_array($ch, $options);
133145
$ResUlt = curl_exec($ch);
134-
//获取 header 部分的大小
146+
//Gets the size of the header
135147
$Header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
136-
//最后一个有效的URL地址
148+
//Gets the last valid URL
137149
$this->HttpUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
138-
//发送的头部请求
150+
//Send header request
139151
$this->HeadersOut = curl_getinfo($ch, CURLINFO_HEADER_OUT );
140-
//获取最后一个代码
152+
//Get the last valid code
141153
$this->HttpCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
142-
//获取Content-Type:值
154+
//Get Content-Type value
143155
//$ContentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE );
144156
if($ResUlt === false || curl_errno($ch) !== 0){
145157
$this->error = curl_error($ch);

0 commit comments

Comments
 (0)