or the specified CURLOPT_STDERR.
|
For the optional parameters of the following options, value should be set to an integer type value:
Options |
OptionalvalueValue |
Remarks |
CURLOPT_BUFFERSIZE |
The size of the cache read into the data obtained each time, but there is no guarantee that this value will be filled every time. |
was added in cURL 7.10. |
##CURLOPT_CLOSEPOLICY
| Either CURLCLOSEPOLICY_LEAST_RECENTLY_USED or CURLCLOSEPOLICY_OLDEST, there are three other CURLCLOSEPOLICYs, but cURL does not support them yet. |
|
##CURLOPT_CONNECTTIMEOUT
The time to wait before initiating a connection. If set to 0, it will wait indefinitely . |
|
|
CURLOPT_CONNECTTIMEOUT_MS
The time to wait for a connection attempt, in milliseconds. If set to 0, wait infinitely. |
was added in cURL 7.16.2. Available starting with PHP 5.2.3. |
|
CURLOPT_DNS_CACHE_TIMEOUT
Set the time to save DNS information in memory, the default is 120 seconds. |
|
|
##CURLOPT_FTPSSLAUTH
FTP verification method: CURLFTPAUTH_SSL | (try SSL first) , CURLFTPAUTH_TLS (try TLS first) or CURLFTPAUTH_DEFAULT (let cURL decide automatically). was added in cURL 7.12.2.
|
| ##CURLOPT_HTTP_VERSION
CURL_HTTP_VERSION_NONE (default value, let cURL decide which version to use), | CURL_HTTP_VERSION_1_0 (force HTTP/1.0) or CURL_HTTP_VERSION_1_1 (force HTTP/1.1).
|
##CURLOPT_INFILESIZE |
Set the size limit of uploaded files in bytes. |
|
##CURLOPT_LOW_SPEED_LIMIT
|
When the transmission speed is less than CURLOPT_LOW_SPEED_LIMIT(bytes/sec ), PHP will determine whether to cancel the transmission because it is too slow based on CURLOPT_LOW_SPEED_TIME. |
| ##CURLOPT_LOW_SPEED_TIME
| When the transmission speed is less than CURLOPT_LOW_SPEED_LIMIT(bytes/sec ), PHP will determine whether to cancel the transmission because it is too slow based on CURLOPT_LOW_SPEED_TIME.
|
##CURLOPT_MAXCONNECTS |
The maximum number of connections allowed, if exceeded, | CURLOPT_CLOSEPOLICY## will be passed #Determine which connections should be stopped.
|
##CURLOPT_MAXREDIRS
| Specifies the maximum number of HTTP redirects. This option is the same as CURLOPT_FOLLOWLOCATION is used together. |
|
CURLOPT_PORT
| is used to specify the connection port. (Optional) Bit field pointers to
|
##CURLOPT_PROTOCOLS |
| CURLPROTO_* . If enabled, the bitfield value limits which protocols libcurl can use during transfers. This will allow you to compile libcurl to support a wide range of protocols, but be restricted to using only a subset of them that are allowed to be used. By default libcurl will use all protocols it supports. See CURLOPT_REDIR_PROTOCOLS | . The available protocol options are: CURLPROTO_HTTP, CURLPROTO_HTTPS, CURLPROTO_FTP, CURLPROTO_FTPS, CURLPROTO_SCP, CURLPROTO_SFTP, CURLPROTO_TELNET, CURLPROTO_LDAP, CURLPROTO_LDAPS, CURLPROTO_DICT, CURLPROTO_FILE, CURLPROTO_TF TP, CURLPROTO_ALL
in cURL 7.19. 4 was added. The bit field refers to |
CURLOPT_PROTOCOLSCURLPROTO_* | . If enabled, the bitfield value limits which protocols libcurl can use during transfers. This will allow you to compile libcurl to support a wide range of protocols, but be restricted to using only a subset of them that are allowed to be used. By default libcurl will use all protocols it supports. See CURLOPT_REDIR_PROTOCOLS | . The available protocol options are: CURLPROTO_HTTP, CURLPROTO_HTTPS, CURLPROTO_FTP, CURLPROTO_FTPS, CURLPROTO_SCP, CURLPROTO_SFTP, CURLPROTO_TELNET, CURLPROTO_LDAP, CURLPROTO_LDAPS, CURLPROTO_DICT, CURLPROTO_FILE, CURLPROTO_TF TP, CURLPROTO_ALL
in cURL 7.19. 4 was added. |
CURLOPT_PROXYAUTHVerification method for HTTP proxy connection. Use the bitfield flags in CURLOPT_HTTPAUTH | to set the corresponding options. For proxy authentication only CURLAUTH_BASIC | and CURLAUTH_NTLM are currently supported. was added in cURL 7.10.7. |
CURLOPT_PROXYPORTThe port of the proxy server. The port can also be set in CURLOPT_PROXY | . |
CURLOPT_PROXYTYPE |
is either CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5. |
was added in cURL 7.10. Bit field value in |
CURLOPT_REDIR_PROTOCOLS |
##CURLPROTO_*. If enabled, the bitfield value will limit the protocols that the transport thread can use when following a redirect when CURLOPT_FOLLOWLOCATION is enabled. This will allow you to restrict the transport thread to a subset of allowed protocols when redirecting. By default libcurl will allow all protocols except FILE and SCP. This is slightly different from the 7.19.4 pre-release version which unconditionally follows all supported protocols. For protocol constants, please refer to CURLOPT_PROTOCOLS.
| was added in cURL 7.19.4. |
CURLOPT_RESUME_FROM
| Pass a byte offset when resuming transmission (used for resumed transmission). |
|
CURLOPT_SSL_VERIFYHOST
| 1 Check whether a common name exists in the server SSL certificate. Translator's Note: Common Name generally means filling in the domain name (domain) or subdomain (sub domain) for which you are going to apply for an SSL certificate. 2 Check that the common name exists and matches the provided host name. |
|
CURLOPT_SSLVERSION
| The SSL version to use (2 or 3). By default PHP will detect this value by itself, although in some cases it may need to be set manually. |
|
##CURLOPT_TIMECONDITION
If after a certain time specified by | CURLOPT_TIMEVALUE If it has been edited, use CURL_TIMECOND_IFMODSINCE to return to the page. If it has not been modified and CURLOPT_HEADER is true, a "304 Not Modified" header will be returned. # If ##CURLOPT_HEADER is false, use CURL_TIMECOND_IFUNMODSINCE. The default value is CURL_TIMECOND_IFUNMODSINCE.
|
|
CURLOPT_TIMEOUT
Set the maximum number of seconds cURL is allowed to execute. |
|
| ##CURLOPT_TIMEOUT_MS
Set the maximum number of milliseconds cURL is allowed to execute. was added in cURL 7.16.2. Available from PHP 5.2.3 onwards. |
|
| CURLOPT_TIMEVALUE
Set a timestamp used by CURLOPT_TIMECONDITION. By default, | CURL_TIMECOND_IFMODSINCE is used .
|
For the optional parameters of the following options, value should be set to a string type value:
Options |
Optional valueValue |
Remarks |
CURLOPT_CAINFO |
One holds 1 or more The file name of the certificate used for verification by the server. This parameter is only meaningful when used with CURLOPT_SSL_VERIFYPEER. . |
|
CURLOPT_CAPATH |
A directory that holds multiple CA certificates. This option is used with CURLOPT_SSL_VERIFYPEER. |
|
##CURLOPT_COOKIE
| Set the "Cookie: " part of the HTTP request Content. Multiple cookies are separated by a semicolon followed by a space (for example, "fruit=apple; colour=red").
|
|
##CURLOPT_COOKIEFILE
The file name containing cookie data. The format of the cookie file can be Netscape format. Or just save the pure HTTP header information to the file. |
|
|
CURLOPT_COOKIEJAR
A file that saves cookie information after the connection is completed. |
|
|
##CURLOPT_CUSTOMREQUEST
Use a custom request message instead | " GET" or "HEAD" as an HTTP request. This is useful for performing "DELETE" or other more covert HTTP requests. Valid values include "GET", "POST", "CONNECT", etc. That is, don't enter the entire HTTP request here. For example, entering "GET /index.html HTTP/1.0\r\n\r\n" is incorrect. Note:Do not use this custom request method until you are sure that the server supports it.
|
|
##CURLOPT_EGDSOCKET
| Similar to CURLOPT_RANDOM_FILE, except for an Entropy Gathering Daemon socket.
|
|
##CURLOPT_ENCODING | "Accept-Encoding: " in the HTTP request header value. Supported encodings are "identity", "deflate" and "gzip". If it is the empty string "", the request header will send all supported encoding types. was added in cURL 7.10. |
|
CURLOPT_FTPPORT
This value will be used to obtain the IP address required for the FTP "POST" command. The "POST" command tells the remote server to connect to the IP address we specified. This string can be a plain text IP address, a hostname, a network interface name (under UNIX) or just a '-' to use the default IP address. |
|
|
##CURLOPT_INTERFACE
The network sending interface name can be an interface name, IP address or a CPU name. |
|
|
CURLOPT_KRB4LEVEL
KRB4 (Kerberos 4) security level. Any of the following values are valid (in order from lowest to highest): "clear" | , "safe", "confidential", "private".. If the string matches none of these, "private" will be used. Setting this option to NULL will disable KRB4 security authentication. Currently KRB4 security authentication can only be used for FTP transmission.
|
| ##CURLOPT_POSTFIELDS
All data is sent using the "POST" operation in the HTTP protocol. To send a file, prefix the file name with @ and use the full path. This parameter can be passed through a urlencoded string like ' | para1=val1¶2=val2&...' or an array with the field name as the key and the field data as the value. If value is an array, the Content-Type header will be set to multipart/form-data.
|
| CURLOPT_PROXY
HTTP proxy channel.
|
|
##CURLOPT_PROXYUSERPWD |
A number used to connect to the proxy"[username]:[ password]" format string.
|
|
##CURLOPT_RANDOM_FILE
|
A file name used to generate SSL random number seeds.
|
| ##CURLOPT_RANGE
| In the form of "X-Y", where X and Y is the range of optional data obtained, measured in bytes. The HTTP transfer thread also supports several such duplicates separated by commas such as "X-Y,N-M".
|
##CURLOPT_REFERER |
In the HTTP request header | "Referer: " content.
|
CURLOPT_SSL_CIPHER_LIST |
A list of SSL encryption algorithms. For example, | RC4-SHA and TLSv1 are both available encryption lists.
|
CURLOPT_SSLCERT |
The name of a file containing a certificate in PEM format. |
| ##CURLOPT_SSLCERTPASSWD |
The password required to use the CURLOPT_SSLCERT | certificate.
|
CURLOPT_SSLCERTTYPE |
Type of certificate. Supported formats are "PEM" (default), "DER" and "ENG". |
was added in cURL 7.9.3. |
CURLOPT_SSLENGINE |
Encryption engine variable used for the SSL private key specified in CURLOPT_SSLKEY. |
|
CURLOPT_SSLENGINE_DEFAULT |
Variables used for asymmetric encryption operations. |
|
CURLOPT_SSLKEY |
The name of the file containing the SSL private key. |
|
##CURLOPT_SSLKEYPASSWD
|
The SSL specified in CURLOPT_SSLKEY The password for the private key.
Note: Since this option contains sensitive password information, remember to keep this PHP script safe.
|
|
##CURLOPT_SSLKEYTYPE | CURLOPT_SSLKEY The encryption type of the private key. The supported key types are "PEM" (default value), "DER" and "ENG".
|
|
##CURLOPT_URL
The URL address that needs to be obtained can also be obtained in curl_init() | Set in function. |
| ##CURLOPT_USERAGENT
Include a "User-Agent: "# in the HTTP request ##Header string.
|
|
##CURLOPT_USERPWD
|
Pass the username and password required for a connection in the format: "[username]:[password]".
|
|
For the optional parameters of the following options, value should be set to an array:
|
OptionsOptionalvalueValue
Remarks |
|
# #CURLOPT_HTTP200ALIASES |
200 response code array, the response in the array is considered a correct response, otherwise it is considered an error.
was added in cURL 7.10.3. |
CURLOPT_HTTPHEADER |
| An array used to set HTTP header fields. Use an array of the following form to set:
array('Content-type: text/plain', 'Content-length: 100')
|
##CURLOPT_POSTQUOTE |
A set of FTP commands executed on the server after the FTP request is executed. |
| ##CURLOPT_QUOTE |
#A set of FTP commands to be executed on the server before the FTP request.
|
For the optional parameters of the following options, value should be set to a stream resource (for example, using fopen()):
Options |
Optional valuevalue |
CURLOPT_FILE |
Set the location of the output file, the value is one Resource type, default is STDOUT (browser). |
CURLOPT_INFILE |
The file address that needs to be read when uploading a file, the value is a resource type. |
CURLOPT_STDERR |
Sets an error output address, the value is a resource type, replacing the default STDERR. |
CURLOPT_WRITEHEADER |
Set the file address where the header part is written, and the value is a resource type. |
For the optional parameters of the following options, value should be set to a callback function name:
Options |
OptionalvalueValue |
##CURLOPT_HEADERFUNCTION
| Set one Callback function, this function has two parameters, the first is the cURL resource handle, and the second is the output header data. The output of header data must rely on this function, which returns the size of the written data. |
CURLOPT_PASSWDFUNCTION
| Set a callback function with three parameters. The first is the cURL resource handle, and the second is a password prompt. character, the third parameter is the maximum allowed password length. Returns the value of the password. |
CURLOPT_PROGRESSFUNCTION
| Set a callback function with three parameters. The first is the resource handle of cURL, and the second is a file description. Character resources, the third one is the length. Returns the contained data. |
CURLOPT_READFUNCTION
| Callback function name. This function should accept three parameters. The first is cURL resource; the second is via options
CURLOPT_INFILE The stream resource passed to cURL; the third parameter is the maximum amount of data that can be read. return
The calling function must return a string whose length is less than or equal to the requested amount of data (the third parameter). Generally from the incoming stream
resource read. Returns the empty string as the EOF (end of file) signal.
|
CURLOPT_WRITEFUNCTION
| Callback function name. This function should accept two parameters. The first is the cURL resource; the second is the data string to be written. number
The data must be saved within the function. The function must return the exact number of bytes passed in to write the data, otherwise the transfer will be hit by an error.
break. |
Return Value Returns TRUE on success, or FALSE on failure.
Update Log
Version | Description |
5.2.10 | Introduced
CURLOPT_PROTOCOLS , and CURLOPT_REDIR_PROTOCOLS .
|
5.1.0 | Introduction
CURLOPT_AUTOREFERER , CURLOPT_BINARYTRANSFER , CURLOPT_FTPSSLAUTH , CURLOPT_PROXYAUTH , and CURLOPT_TIMECONDITION .
|
5.0.0 | Introduction
CURLOPT_FTP_USE_EPRT , CURLOPT_NOSIGNAL , CURLOPT_UNRESTRICTED_AUTH , CURLOPT_BUFFERSIZE , CURLOPT_HTTPAUTH , CURLOPT_PROXYPORT , CURLOPT_PROXYTYPE , CURLOPT_SSLCERTTYPE , and CURLOPT_HTTP200ALIASES .
|
实例
初始化一个新的cURL会话并获取一个网页 <?php
// 创建一个新cURL资源
$ch = curl_init();
// 设置URL和相应的选项
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, false);
// 抓取URL并把它传递给浏览器
curl_exec($ch);
//关闭cURL资源,并且释放系统资源
curl_close($ch);
?> 上传文件实例: <?php
/* http://localhost/upload.php:
print_r($_POST);
print_r($_FILES);
*/
$ch = curl_init();
$data = array('name' => 'Foo', 'file' => '@/home/user/test.png');
curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
?> 以上实例输出结果如下: Array
(
[name] => Foo
)
Array
(
[file] => Array
(
[name] => test.png
[type] => image/png
[tmp_name] => /tmp/phpcpjNeQ
[error] => 0
[size] => 279
)
) 注释
传递一个数组到CURLOPT_POSTFIELDS,cURL会把数据编码成 multipart/form-data,而然传递一个URL-encoded字符串时,数据会被编码成 application/x-www-form-urlencoded。
推荐学习:《PHP视频教程》
##
');
var statusdiv=$('#comment-status');
commentform.submit(function(e){
e.preventDefault();
var noteContent = editor.getValue();
// console.log(noteContent);
noteContent = noteContent.replace(/<code>/g,"<pre class="brush:php;toolbar:false">");
noteContent = noteContent.replace(//g," ");
// 系列化表单数据
var comment_parent = 0;
var is_user_logged_in = $("#is_user_logged_in").val();
var comment_post_ID = 6085;
var _wp_unfiltered_html_comment = $("#_wp_unfiltered_html_comment").val();
var comment = noteContent;
var author = $("#author").val();
var url = $("#url").val();
var email = $("#email").val();
if(isBlank(author) && is_user_logged_in==0) {
statusdiv.html('请输入昵称! ').show();
} else if(isBlank(email) && is_user_logged_in==0) {
statusdiv.html('请输入邮箱! ').show();
} else {
// var formdata=commentform.serialize() + "&comment=" + noteContent ;
// 添加状态信息
statusdiv.html('Processing... ').show();
// 获取表单提交地址
var formurl=commentform.attr('action');
// 异步提交
$.ajax({
type: 'post',
url: formurl,
dataType:'json',
data: {"comment_parent":comment_parent,"comment_post_ID":comment_post_ID, "_wp_unfiltered_html_comment":_wp_unfiltered_html_comment,"comment":comment,"url":url, "email":email,"author":author},
error: function(XMLHttpRequest, textStatus, errorThrown){
statusdiv.html('数据不完整或表单提交太快了! ').show();
},
success: function(data, textStatus){
if(data.errorno=="0") {
$("#submit").prop('disabled', true);
statusdiv.html('笔记已提交审核,感谢分享笔记! ').show();
alert('笔记已提交审核,感谢分享笔记!');
}else{
statusdiv.html(''+data.msg+' ').show();
}
commentform.find('textarea[name=comment]').val('');
}
});
setTimeout(function(){
$("#submit").prop('disabled', false);
}, 10*1000);
}
return false;
});
$(".comt-author").click(function() {
href = $(this).children("a").attr("href");
if(href.indexOf("/note/")!=-1) {
var win = window.open(href, '_blank');
win.focus();
}
});
$(".comt-meta span").hover(function(){
$(this).children(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
},function(){
$(this).children(".tooltip").removeAttr("style");
});
/*
$(".wrapper i").hover(function(){
$(this).siblings(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
},function(){
$(this).siblings(".tooltip").css({ "opacity": 0, "pointer-events": "auto"});
});
*/
//Upvote.create('runoobvote-id', {callback: vote_callback});
var ajaxurl = 'https://www.runoob.com/wp-admin/admin-ajax.php';
var callback = function(data) {
//console.log($('#runoobvote-id').upvote('upvoted'));
//console.log($('#runoobvote-id').upvote('downvoted'));
//console.log(data);
_vote_action = data.action;
id_arr = data.id.split('-');
um_id= id_arr[2];
//console.log(um_id);
var re = /^[1-9]+/;
if (re.test(um_id)) {
var ajax_data = {
_vote_action: _vote_action,
action: "pinglun_zan",
um_id: um_id,
um_action: "ding"
};
//console.log(ajax_data);
$.post(ajaxurl,ajax_data,function(status){
//if(status.vote_num>999) {
// _voteHtml = ''+kFormatter(status.vote_num) +'';
// $("#runoobvote-id-" + um_id + " .count").hide().after(_voteHtml);
//}
});
}
};
if($('#comments').length){
$('.upvotejs').upvote({id: 6085, callback: callback});
$.post(ajaxurl,{"action":"pinglun_zan","postid":6085},function(data){
$(data).each(function(key,value) {
$("#runoobvote-id-" + value.commid + " .upvote").addClass(value.upvotejs_class);
$("#runoobvote-id-" + value.commid + " .downvote").addClass(value.downvote_class);
$("#runoobvote-id-" + value.commid + " .count").text(value.upvote_count);
})
},'json');
}
});
function isBlank(str) {
return (!str || /^\s*$/.test(str));
}
function kFormatter(num) {
// return num;
return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
}
|
|
|