Home  >  Article  >  Backend Development  >  PHP CURL curl_setopt parameter

PHP CURL curl_setopt parameter

WBOY
WBOYOriginal
2016-08-08 09:24:271002browse

PHP CURL curl_setopt parameters

bool curl_setopt (int ch, string option, mixed value)
curl_setopt() function will set options for a CURL session. The option parameter is the setting you want, and value is the value given by this option.


The values ​​of the following options will be used as long integers (specified in the option parameter): CURLOPT_INFILESIZE: When you upload a file to the remote site, this option tells PHP the size of the file you are uploading. ? CURLOPT_VERBOSE : If you want CURL to report every unexpected event, set this option to a non-zero value.
? CURLOPT_HEADER : If you want to include a header in the output, set this option to a non-zero value.
? CURLOPT_NOPROGRESS: If you don't want PHP to display a progress bar for CURL transfers, set this option to a non-zero value. Note: PHP automatically sets this option to a non-zero value, you should only change this option for debugging purposes.
? CURLOPT_NOBODY : If you don’t want to include the body part in the output, set this option to a non-zero value.
? CURLOPT_FAILONERROR: If you want PHP not to display when an error occurs (HTTP code return greater than or equal to 300), set this option to a non-zero value. The default behavior is to return a normal page and ignore the code.
? CURLOPT_UPLOAD: If you want PHP to prepare for uploading, set this option to a non-zero value.
? CURLOPT_POST: If you want PHP to do a regular HTTP POST, set this option to a non-zero value. This POST is of the ordinary application/x-www-from-urlencoded type, mostly used by HTML forms.
? CURLOPT_FTPLISTONLY: Set this option to a non-zero value and PHP will list the FTP directory name list.
? CURLOPT_FTPAPPEND : Set this option to a non-zero value and PHP will apply the remote file instead of overwriting it.
? CURLOPT_NETRC: Set this option to a non-zero value and PHP will look in your ~./netrc file for the username and password of the remote site you want to connect to.
? CURLOPT_FOLLOWLOCATION : Set this option to a non-zero header (like "Location: "), and the server will send it as part of the HTTP header (note that this is recursive, PHP will send a header like "Location: ") ).
? CURLOPT_PUT : Set this option to a non-zero value to upload a file using HTTP. To upload this file, the CURLOPT_INFILE and CURLOPT_INFILESIZE options must be set.
? CURLOPT_MUTE: Set this option to a non-zero value, and PHP will be completely silent for the CURL function.
? CURLOPT_TIMEOUT: Set a long integer as the maximum number of seconds.
? CURLOPT_LOW_SPEED_LIMIT: Set a long integer to control how many bytes are transmitted.
? CURLOPT_LOW_SPEED_TIME: Set a long integer to control how many seconds to transmit the number of bytes specified by CURLOPT_LOW_SPEED_LIMIT.
? CURLOPT_RESUME_FROM: Pass a long integer parameter containing the byte offset address (the start form you want to transfer to).
? CURLOPT_SSLVERSION: Pass a long parameter containing the SSL version. By default PHP will be determined by its own efforts, in more security you have to set it manually.
? CURLOPT_TIMECONDITION: Pass a long parameter to specify how to handle the CURLOPT_TIMEVALUE parameter. You can set this parameter to TIMECOND_IFMODSINCE or TIMECOND_ISUNMODSINCE. This is only for HTTP.
? CURLOPT_TIMEVALUE: Pass a number of seconds from 1970-1-1 to now. This time will be used as the specified value by the CURLOPT_TIMEVALUE option, or by the default TIMECOND_IFMODSINCE.

The values ​​of the following options will be treated as strings:
? CURLOPT_URL: This is the URL address you want to retrieve using PHP. You can also set this option during initialization with the curl_init() function.
? CURLOPT_USERPWD: Pass a string in the form of [username]:[password] and use PHP to connect.
? CURLOPT_PROXYUSERPWD: Pass a string in the format [username]:[password] to connect to the HTTP proxy.
? CURLOPT_RANGE: Pass a range you want to specify. It should be in "X-Y" format, with X or Y being excluded. HTTP transfers also support several intervals, separated by commas (X-Y,N-M).
? CURLOPT_POSTFIELDS: Pass a string containing all the data as an HTTP "POST" operation.
? CURLOPT_REFERER: A string containing a "referer" header in the HTTP request.
? CURLOPT_USERAGENT: A string containing a "user-agent" header in the HTTP request.
? CURLOPT_FTPPORT: Pass an IP address containing the IP address used by the ftp "POST" command. This POST instruction tells the remote server to connect to the IP address we specified. This string can be an IP address, a host name, a network interface name (under UNIX), or '-' (use the system default IP address).
? CURLOPT_COOKIE: Pass a header connection containing an HTTP cookie.
? CURLOPT_SSLCERT: Pass a string containing the certificate in PEM format.
? CURLOPT_SSLCERTPASSWD: Pass a password containing the necessary password to use the CURLOPT_SSLCERT certificate.
? CURLOPT_COOKIEFILE: Pass a string containing the name of the file containing cookie data. This cookie file can be in Netscape format, or it can be a stack of HTTP-style headers stored in the file.
? CURLOPT_CUSTOMREQUEST: When making an HTTP request, pass a character to be used by GET or HEAD. Pass a string to be used instead of GET or HEAD when doing an HTTP request. This is useful for doing or another, more obscure, HTTP request. Note: Make sure your server supports Order not to do it yet. The following options require a file description (obtained by using the fopen() function):
? CURLOPT_FILE: This file will be the output file you place and transmit. The default is STDOUT.
? CURLOPT_INFILE: This file will be the input file you transmit.
? CURLOPT_WRITEHEADER: This file contains the header part of your output.
? CURLOPT_STDERR : This file has errors written instead of stderr. Examples used to obtain pages that require login. The current method is to log in once every time. Those who need it will make improvements.

Example 1:

<span>$cookie_jar</span> = <span>tempnam</span>('./tmp','cookie'<span>); </span><span>$ch</span> = curl_init(); curl_setopt(<span>$ch</span>,CURLOPT_URL, 'http://******'<span>); curl_setopt(</span><span>$ch</span>, CURLOPT_POST, 1<span>); </span><span>$request</span> = 'email_address=&password=&action='<span>; curl_setopt(</span><span>$ch</span>, CURLOPT_POSTFIELDS, <span>$request</span>); <span>//</span><span>把返回来的cookie信息保存在$cookie_jar文件中</span> curl_setopt(<span>$ch</span>, CURLOPT_COOKIEJAR, <span>$cookie_jar</span>); <span>//</span><span>设定返回的数据是否自动显示</span> curl_setopt(<span>$ch</span>, CURLOPT_RETURNTRANSFER, 1); <span>//</span><span>设定是否显示头信息</span> curl_setopt(<span>$ch</span>, CURLOPT_HEADER, <span>false</span>); <span>//</span><span>设定是否输出页面内容</span> curl_setopt(<span>$ch</span>, CURLOPT_NOBODY, <span>false</span><span>); curl_exec(</span><span>$ch</span><span>); curl_close(</span><span>$ch</span>); <span>//</span><span>get data after login</span><p><span><img src="http://image.codes51.com/Article/image/20150512/20150512174030_8511.jpg" alt=""></span></p><p>Example Two: </p><divcourier new><p><span><img src="http://image.codes51.com/Article/image/20150512/20150512174030_8667.jpg" alt=""></span></p> <precourier new><span>$ch2</span> =<span> curl_init(); curl_setopt(</span><span>$ch2</span>, CURLOPT_URL, 'http://*****'<span>); curl_setopt(</span><span>$ch2</span>, CURLOPT_HEADER, <span>false</span><span>); curl_setopt(</span><span>$ch2</span>, CURLOPT_RETURNTRANSFER, 1<span>); curl_setopt(</span><span>$ch2</span>, CURLOPT_COOKIEFILE, <span>$cookie_jar</span><span>); </span><span>$orders</span> = curl_exec(<span>$ch2</span><span>); </span><span>echo</span> ''<span>; </span><span>echo</span><span>strip_tags</span>(<span>$orders</span><span>); </span><span>echo</span> ''<span>; curl_close(</span><span>$ch2</span>); 实践证明很稳定:)<p><span><img src="http://image.codes51.com/Article/image/20150512/20150512174030_8667.jpg" alt=""></span></p><p>Example three: </p><divcourier new><p><span><img src="http://image.codes51.com/Article/image/20150512/20150512174030_8823.jpg" alt=""></span></p> <precourier new><span>set_time_limit</span>(0<span>); </span><span>function</span><span> _rand() { </span><span>$length</span>=26<span>; </span><span>$chars</span> = "0123456789abcdefghijklmnopqrstuvwxyz"<span>; </span><span>$max</span> = <span>strlen</span>(<span>$chars</span>) - 1<span>; </span><span>mt_srand</span>((<span>double</span>)<span>microtime</span>() * 1000000<span>); </span><span>$string</span> = ''<span>; </span><span>for</span>(<span>$i</span> = 0; <span>$i</span> < <span>$length</span>; <span>$i</span>&#43;&#43;<span>) { </span><span>$string</span> .= <span>$chars</span>[<span>mt_rand</span>(0, <span>$max</span><span>)]; } </span><span>return</span><span>$string</span><span>; } </span><span>$HTTP_SESSION</span>=<span>_rand(); </span><span>echo</span><span>$HTTP_SESSION</span><span>; </span><span>$HTTP_Server</span>="www.baidu.com"<span>; </span><span>$HTTP_URL</span>="/"<span>; </span><span>$ch</span> =<span> curl_init(); curl_setopt (</span><span>$ch</span>,CURLOPT_URL,"http://".<span>$HTTP_Server</span>.<span>$HTTP_URL</span><span>); curl_setopt(</span><span>$ch</span>,CURLOPT_RETURNTRANSFER,<span>true</span><span>); curl_setopt(</span><span>$ch</span>,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"<span>); </span><span>//</span><span>curl_setopt($ch,CURLOPT_COOKIE,$HTTP_SESSION);</span><span>$res</span> = curl_exec(<span>$ch</span><span>); curl_close (</span><span>$ch</span><span>); </span><span>print_r</span>(<span>$res</span>);


Flash forum code:
1. Cookie grabbing program:

<span>$URL</span>="http://www.yoururl.com/bbs/login.asp?action=chk"<span>; </span><span>//</span><span>填入论坛的登陆页面地址</span><span>$ch</span> =<span> curl_init(); curl_setopt(</span><span>$ch</span>,CURLOPT_URL,<span>$URL</span><span>); curl_setopt(</span><span>$ch</span>,CURLOPT_REFERER,"http://www.hxfoods.com/bbs/login.asp"<span>); </span><span>//</span><span>设置,访问页面的来源地址</span><span> curl_setopt(</span><span>$ch</span>,CURLOPT_POST,1<span>); curl_setopt(</span><span>$ch</span>,CURLOPT_POSTFIELDS,'username=→→敢死队→&password=168168'<span>); </span><span>//</span><span>分析登陆页面,把用户名,密码分别对应起来</span> curl_setopt (<span>$ch</span>, CURLOPT_HEADER,<span>true</span><span>); </span><span>//</span><span>使能显示http头,</span> curl_exec(<span>$ch</span><span>); </span><span>if</span> (curl_errno(<span>$ch</span><span>)) { </span><span>print</span> curl_error(<span>$ch</span><span>); } </span><span>else</span><span> { curl_close(</span><span>$ch</span><span>); }</span>

2. Clean the building:

<span>set_time_limit</span>(0<span>); </span><span>//</span><span>设置程序执行时间无限制</span><span>$i</span>=10000<span>; </span><span>//</span><span>耍10000次</span><span>for</span>(<span>$j</span>=0;<span>$j</span><<span>$i</span>;<span>$j</span>&#43;&#43;<span>) { </span><span>$URL</span>="http://www.yoururl.com/bbs/savepost.asp"<span>; </span><span>//</span><span>这个地址是回复表单里面action的url地址</span><span>$ch</span> =<span> curl_init(); curl_setopt(</span><span>$ch</span>,CURLOPT_URL,<span>$URL</span><span>); curl_setopt(</span><span>$ch</span>,CURLOPT_REFERER,"http://www.hxfoods.com/bbs/dispbbs.asp?boardid=14&replyid=672709&id=127437&page=1&skin=0&Star=53"<span>); </span><span>//</span><span>设置来源地址,如果不设置,论坛服务器有可能有验证不允许回复</span> curl_setopt(<span>$ch</span>,CURLOPT_COOKIESESSION,<span>true</span><span>); </span><span>//</span><span>能保存cookie</span> curl_setopt(<span>$ch</span>,CURLOPT_COOKIE,"DvForum=userid=24122&usercookies=0&userhidden=2&password=w0reu3g775VrY745&userclass=%96%7C&username=%A1%FA%A1%FA%B8%D2%CB%C0%B6%D3%A1%FA&StatUserID=2194783945 "<span>); </span><span>//</span><span>这儿就是设置cookie了</span> curl_setopt(<span>$ch</span>,CURLOPT_POST,1<span>); curl_setopt(</span><span>$ch</span>,CURLOPT_NOBODY,1<span>); </span><span>//</span><span>不显示内容,因为有很多论坛回复后要自动跳转。</span> curl_setopt(<span>$ch</span>,CURLOPT_POSTFIELDS,'Body=gfdfgdfgasdfgdfgdfgdfg& followup=672709&RootID=127437&star=58&TotalUseTable=Dv_bbs3& amp;UserName=→→敢死队→&signflag=1&total=65535'<span>); </span><span>//</span><span>把你分析的回复表单的参数分别赋&#20540;</span> curl_setopt (<span>$ch</span>, CURLOPT_HEADER,<span>true</span><span>); curl_exec(</span><span>$ch</span><span>); </span><span>if</span> (curl_errno(<span>$ch</span><span>)) { </span><span>print</span> curl_error(<span>$ch</span><span>); } </span><span>else</span><span> { curl_close(</span><span>$ch</span><span>); } }</span>

CURL related functions

curl_close — 关闭一个curl会话
curl_copy_handle — 拷贝一个curl连接资源的所有内容和参数
curl_errno — 返回一个包含当前会话错误信息的数字编号
curl_error — 返回一个包含当前会话错误信息的字符串
curl_exec — 执行一个curl会话
curl_getinfo — 获取一个curl连接资源句柄的信息
curl_init — 初始化一个curl会话
curl_multi_add_handle — 向curl批处理会话中添加单独的curl句柄资源
curl_multi_close — 关闭一个批处理句柄资源
curl_multi_exec — 解析一个curl批处理句柄
curl_multi_getcontent — 返回获取的输出的文本流
curl_multi_info_read — 获取当前解析的curl的相关传输信息
curl_multi_init — 初始化一个curl批处理句柄资源
curl_multi_remove_handle — 移除curl批处理句柄资源中的某个句柄资源
curl_multi_select — Get all the sockets associated with the cURL extension, which can then be "selected"
curl_setopt_array — 以数组的形式为一个curl设置会话参数
curl_setopt — 为一个curl设置会话参数
curl_version — 获取curl相关的版本信息


curl_init()函数的作用初始化一个curl会话,curl_init()函数唯一的一个参数是可选的,表示一个url地址。
curl_exec()函数的作用是执行一个curl会话,唯一的参数是curl_init()函数返回的句柄。
curl_close()函数的作用是关闭一个curl会话,唯一的参数是curl_init()函数返回的句柄。

<span>$ch</span> = curl_init("http://www.baidu.com/"<span>); curl_exec(</span><span>$ch</span><span>); curl_close(</span><span>$ch</span>);

curl_version()函数的作用是获取curl相关的版本信息,curl_version()函数有一个参数,不清楚是做什么的

<span>print_r</span>(curl_version())


curl_getinfo()函数的作用是获取一个curl连接资源句柄的信息,curl_getinfo()函数有两个参数,第一个参数是curl的资源句柄,第二个参数是下面一些常量:

<span>$ch</span> = curl_init("http://www.baidu.com/"<span>); </span><span>print_r</span>(curl_getinfo(<span>$ch</span>));

可选的常量包括:
CURLINFO_EFFECTIVE_URL
最后一个有效的url地址
CURLINFO_HTTP_CODE
最后一个收到的HTTP代码
CURLINFO_FILETIME
远程获取文档的时间,如果无法获取,则返回值为“-1”
CURLINFO_TOTAL_TIME
最后一次传输所消耗的时间
CURLINFO_NAMELOOKUP_TIME
名称解析所消耗的时间
CURLINFO_CONNECT_TIME
建立连接所消耗的时间
CURLINFO_PRETRANSFER_TIME
从建立连接到准备传输所使用的时间
CURLINFO_STARTTRANSFER_TIME
从建立连接到传输开始所使用的时间
CURLINFO_REDIRECT_TIME
在事务传输开始前重定向所使用的时间
CURLINFO_SIZE_UPLOAD
上传数据量的总值
CURLINFO_SIZE_DOWNLOAD
下载数据量的总值
CURLINFO_SPEED_DOWNLOAD
平均下载速度
CURLINFO_SPEED_UPLOAD
平均上传速度
CURLINFO_HEADER_SIZE
header部分的大小
CURLINFO_HEADER_OUT
发送请求的字符串
CURLINFO_REQUEST_SIZE
在HTTP请求中有问题的请求的大小
CURLINFO_SSL_VERIFYRESULT
Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER
CURLINFO_CONTENT_LENGTH_DOWNLOAD
从Content-Length: field中读取的下载内容长度
CURLINFO_CONTENT_LENGTH_UPLOAD
上传内容大小的说明
CURLINFO_CONTENT_TYPE
下载内容的“Content-type”值,NULL表示服务器没有发送有效的“Content-Type: header”
curl_setopt()函数的作用是为一个curl设置会话参数。curl_setopt_array()函数的作用是以数组的形式为一个curl设置会话参数。

$ch = curl_init(); $fp = fopen("example_homepage.txt", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); $options = array( CURLOPT_URL => 'http://www.baidu.com/', CURLOPT_HEADER => false ); curl_setopt_array($ch, $options); curl_exec($ch); curl_close($ch); fclose($fp);


The parameters that can be set are:
CURLOPT_AUTOREFERER
Automatically set the referer information in the header
CURLOPT_BINARYTRANSFER
When CURLOPT_RETURNTRANSFER is enabled, the data will be returned
CURLOPT_COOKIESESSION
When enabled, curl will only pass a session cookie and ignore others cookie, default In this case curl will return all cookies to the server. Session cookies refer to cookies that are used to determine whether the server-side session is valid.
CURLOPT_CRLF
When enabled, convert Unix line feed characters into carriage return and line feed characters.
CURLOPT_DNS_USE_GLOBAL_CACHE
When enabled, a global DNS cache is enabled. This item is thread-safe and defaults to true.
CURLOPT_FAILONERROR
Displays the HTTP status code. The default behavior is to ignore HTTP information with a number less than or equal to 400.
CURLOPT_FILETIME
When enabled, it will try to modify the information in the remote document. The result information will be returned through the CURLINFO_FILETIME option of the curl_getinfo() function.
CURLOPT_FOLLOWLOCATION
When enabled, the "Location:" returned by the server will be placed in the header and returned to the server recursively. Use CURLOPT_MAXREDIRS to limit the number of recursive returns.
CURLOPT_FORBID_REUSE
Forcibly disconnect after completing the interaction and cannot be reused.
CURLOPT_FRESH_CONNECT
Force a new connection to replace the one in the cache.
CURLOPT_FTP_USE_EPRT
TRUE to use EPRT (and LPRT) when doing active FTP downloads. Use FALSE to disable EPRT and LPRT and use PORT only.
Added in PHP 5.0.0.
CURLOPT_FTP_USE_EPSV
TRUE to first try an EPSV command for FTP transfers before reverting back to PASV. Set to FALSE to disable EPSV.
CURLOPT_FTPAPPEND
TRUE to append to the remote file instead of overwriting it.
CURLOPT_FTPASCII
An alias of CURLOPT_TRANSFERTEXT. Use that instead.
CURLOPT_FTPLISTONLY
TRUE to only list the names of an FTP directory.
CURLOPT_HEADER
When enabled, the header file information will be output as a data stream.
CURLOPT_HTTPGET
When enabled, the HTTP method will be set to GET. Because GET is the default, it is only used when it is modified.
CURLOPT_HTTPPROXYTUNNEL
When enabled, it will be transmitted through HTTP proxy.
CURLOPT_MUTE
Restore all modified parameters in the curl function to their default values.
CURLOPT_NETRC
After the connection is established, access the ~/.netrc file to obtain the username and password information to connect to the remote site.
CURLOPT_NOBODY
When enabled, the body part in HTML will not be output.
CURLOPT_NOPROGRESS
Turn off the progress bar of curl transmission when enabled. The default setting of this item is true
CURLOPT_NOSIGNAL
Ignore all signals passed by curl to PHP when enabled. This item is turned on by default during SAPI multi-thread transmission.
CURLOPT_POST
When enabled, a regular POST request will be sent of type: application/x-www-form-urlencoded, just like a form submission.
CURLOPT_PUT
When enabled, HTTP is allowed to send files. CURLOPT_INFILE and CURLOPT_INFILESIZE must be set at the same time.
CURLOPT_RETURNTRANSFER
The information obtained by curl_exec() is returned in the form of a file stream instead of being output directly.
CURLOPT_SSL_VERIFYPEER
FALSE to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2). TRUE by default as of cURL 7.10. Default bundle installed as of cURL 7.10.
CURLOPT_TRANSFERTEXT
TRUE to use ASCII mode for FTP transfers. in plain text instead of HTML. On Windows systems, it will not set STDOUT to binary mode.
CURLOPT_UNRESTRICTED_AUTH
Continuously append username and password information to multiple locations in the header generated using CURLOPT_FOLLOWLOCATION, even if the domain name has changed.
CURLOPT_UPLOAD
Allows file transfer when enabled
CURLOPT_VERBOSE
When enabled, all information will be reported and stored in STDERR or the specified CURLOPT_STDERR
CURLOPT_BUFFERSIZE
The size of the cache is read each time the data is obtained, and this value will be filled every time .
CURLOPT_CLOSEPOLICY
It is either CURLCLOSEPOLICY_LEAST_RECENTLY_USED or CURLCLOSEPOLICY_OLDEST. There are three others, but curl does not support them yet. .
CURLOPT_CONNECTTIMEOUT
The time to wait before initiating a connection. If set to 0, there will be no waiting.
CURLOPT_DNS_CACHE_TIMEOUT
Set the time to save DNS information in memory, the default is 120 seconds.
CURLOPT_FTPSSLAUTH
The FTP authentication method (when is activated): CURLFTPAUTH_SSL (try SSL first), CURLFTPAUTH_TLS (try TLS first), or CURLFTPAUTH_DEFAULT (let cURL decide).
CURLOPT_HTTP_VERSION
Set the HTTP protocol used by curl, CURL_HTTP_VERSION_NONE (let curl myself Judgment), CURL_HTTP_VERSION_1_0 (HTTP/1.0), CURL_HTTP_VERSION_1_1 (HTTP/1.1)
CURLOPT_HTTPAUTH
The HTTP verification method used, the optional values ​​are: CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, CURLAUTH_NTLM, CURLAUTH_ANY, CURLAU TH_ANYSAFE, you can use the "|" operator Separate multiple values, curl lets the server choose the one with the best support, CURLAUTH_ANY is equivalent to CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM, CURLAUTH_ANYSAFE is equivalent to CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM
CURLOPT_INFILESIZE
Set the size of the uploaded file
CURLOPT_LOW_SPEED_LIMIT
When the transfer speed is less than CURLOPT_LOW_SPEED_LIMIT, PHP will use CURLOPT_LOW_SPEED_TIME to determine whether to cancel the transfer because it is too slow.
CURLOPT_LOW_SPEED_TIME
The number of seconds the transfer should be below CURLOPT_LOW_SPEED_LIMIT for PHP to consider the transfer too slow and abort.
CURLOPT_MAXCONNECTS
The maximum number of connections allowed. If exceeded, CURLOPT_CLOSEPOLICY will be used to determine which connections should be stopped.
CURLOPT_MAXREDIRS
Specify the maximum number of HTTP redirects. This option is used together with CURLOPT_FOLLOWLOCATION.
CURLOPT_PORT
An optional quantity used to specify the connection port
CURLOPT_PROXYAUTH
The HTTP authentication method(s) to use for the proxy connection. Use the same bitmasks as described in CURLOPT_HTTPAUTH. For proxy authentication, only CURLAUTH_BASIC and CURLAUTH_NTLM are currently
CURLOPT_PROXYPORT
The port number of the proxy to connect to. (Used to resume downloading from breakpoints)
CURLOPT_SSL_VERIFYHOST
1 to check the existence of a common name in the SSL peer certificate.
2 to check the existence of a common name and also verify that it matches the hostname provided.
CURLOPT_SSLVERSION
The SSL version (2 or 3) to use. By default PHP will try to determine this itself, although in some cases this must be set manually.
CURLOPT_TIMECONDITION
If edited after a certain time specified by CURLOPT_TIMEVALUE, use CURL_TIMECOND_IFMODSINCE to return If the page has not been modified and CURLOPT_HEADER is true, a "304 Not Modified" header will be returned. If CURLOPT_HEADER is false, CURL_TIMECOND_ISUNMODSINCE will be used. The default value is CURL_TIMECOND_IFMODSINCE
CURLOPT_TIMEOUT
Set the maximum number of seconds curl is allowed to execute
CURLOPT_TIMEVALUE
Set a timestamp used by CURLOPT_TIMECONDITION. By default, CURL_TIMECOND_IFMODSINCE is used.
CURLOPT_CAINFO
The name of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with CURLOPT_SSL_VERIFYPEER.
CURLOPT_CAPATH
A directory that holds multiple CA certificates. Use this option alongside CURLOPT_SSL_VERIFYPEER.
CURLOPT_COOKIE
Set the content of the "Set-Cookie:" part of the HTTP request.
CURLOPT_COOKIEFILE
The name of the file containing cookie information. This cookie file can be Netscape format or HTTP style header information.
CURLOPT_COOKIEJAR
The name of the file that stores cookie information after the connection is closed
CURLOPT_CUSTOMREQUEST
A custom request method to use instead of "GET" or "HEAD" when doing a HTTP request. This is useful for doing "DELETE" or other, more obscure HTTP requests. Valid values ​​are things like "GET", "POST", "CONNECT" and so on; i.e. Do not enter a whole HTTP request line here. For instance, entering "GET /index.html HTTP/1.0rnrn" would be incorrect.
Note: Don't do this without making sure the server supports the custom request method first.
CURLOPT_EGBSOCKET
Like CURLOPT_RANDOM_FILE, except a filename to an Entropy Gathering Daemon socket.
CURLOPT_ENCODING
The content of the "Accept-Encoding:" part of the header. The supported encoding formats are: "identity", "deflate", "gzip".如果设置为空字符串,则表示支持所有的编码格式
CURLOPT_FTPPORT
The value which will be used to get the IP address to use for the FTP "POST" instruction. The "POST" instruction tells the remote server to connect to our specified IP address. The string may be a plain IP address, a hostname, a network interface name (under Unix), or just a plain '-' to use the systems default IP address.
CURLOPT_INTERFACE
在外部网络接口中使用的名称,可以是一个接口名,IP或者主机名。
CURLOPT_KRB4LEVEL
KRB4(Kerberos 4)安全级别的设置,可以是一下几个值之一:"clear","safe","confidential","private"。默认的值 为"private",设置为null的时候表示禁用KRB4,现在KRB4安全仅能在FTP传输中使用。
CURLOPT_POSTFIELDS
在HTTP中的“POST”操作。如果要传送一个文件,需要一个@开头的文件名
CURLOPT_PROXY
设置通过的HTTP代理服务器
CURLOPT_PROXYUSERPWD
连接到代理服务器的,格式为“[username]:[password]”的用户名和密码。
CURLOPT_RANDOM_FILE
设定存放SSL用到的随机数种子的文件名称
CURLOPT_RANGE
设置HTTP传输范围,可以用“X-Y”的形式设置一个传输区间,如果有多个HTTP传输,则使用逗号分隔多个值,形如:"X-Y,N-M"。
CURLOPT_REFERER
设置header中"Referer: " 部分的值。
CURLOPT_SSL_CIPHER_LIST
A list of ciphers to use for SSL. For example, RC4-SHA and TLSv1 are valid cipher lists.
CURLOPT_SSLCERT
传递一个包含PEM格式证书的字符串。
CURLOPT_SSLCERTPASSWD
传递一个包含使用CURLOPT_SSLCERT证书必需的密码。
CURLOPT_SSLCERTTYPE
The format of the certificate. Supported formats are "PEM" (default), "DER", and "ENG".
CURLOPT_SSLENGINE
The identifier for the crypto engine of the private SSL key specified in CURLOPT_SSLKEY.
CURLOPT_SSLENGINE_DEFAULT
The identifier for the crypto engine used for asymmetric crypto operations.
CURLOPT_SSLKEY
The name of a file containing a private SSL key.
CURLOPT_SSLKEYPASSWD
The secret password needed to use the private SSL key specified in CURLOPT_SSLKEY.
Note: Since this option contains a sensitive password, remember to keep the PHP script it is contained within safe.
CURLOPT_SSLKEYTYPE
The key type of the private SSL key specified in CURLOPT_SSLKEY. Supported key types are "PEM" (default), "DER", and "ENG".
CURLOPT_URL
需要获取的URL地址,也可以在PHP的curl_init()函数中设置。
CURLOPT_USERAGENT
在HTTP请求中包含一个”user-agent”头的字符串。
CURLOPT_USERPWD
传递一个连接中需要的用户名和密码,格式为:“[username]:[password]”。
CURLOPT_HTTP200ALIASES
设置不再以error的形式来处理HTTP 200的响应,格式为一个数组。
CURLOPT_HTTPHEADER
设置一个header中传输内容的数组。
CURLOPT_POSTQUOTE
An array of FTP commands to execute on the server after the FTP request has been performed.
CURLOPT_QUOTE
An array of FTP commands to execute on the server prior to the FTP request.
CURLOPT_FILE
设置输出文件的位置,值是一个资源类型,默认为STDOUT (浏览器)。
CURLOPT_INFILE
在上传文件的时候需要读取的文件地址,值是一个资源类型。
CURLOPT_STDERR
设置一个错误输出地址,值是一个资源类型,取代默认的STDERR。
CURLOPT_WRITEHEADER
设置header部分内容的写入的文件地址,值是一个资源类型。
CURLOPT_HEADERFUNCTION
设置一个回调函数,这个函数有两个参数,第一个是curl的资源句柄,第二个是输出的header数据。header数据的输出必须依赖这个函数,返回已写入的数据大小。
CURLOPT_PASSWDFUNCTION
设置一个回调函数,有三个参数,第一个是curl的资源句柄,第二个是一个密码提示符,第三个参数是密码长度允许的最大值。返回密码的值。
CURLOPT_READFUNCTION
设置一个回调函数,有两个参数,第一个是curl的资源句柄,第二个是读取到的数据。数据读取必须依赖这个函数。返回读取数据的大小,比如0或者EOF。
CURLOPT_WRITEFUNCTION
设置一个回调函数,有两个参数,第一个是curl的资源句柄,第二个是写入的数据。数据写入必须依赖这个函数。返回精确的已写入数据的大小


curl_copy_handle()函数的作用是拷贝一个curl连接资源的所有内容和参数

$ch = curl_init("http://www.baidu.com/"); $another = curl_copy_handle($ch); curl_exec($another); curl_close($another);

curl_error()函数的作用是返回一个包含当前会话错误信息的字符串。
curl_errno()函数的作用是返回一个包含当前会话错误信息的数字编号。


curl_multi_init()函数的作用是初始化一个curl批处理句柄资源。
curl_multi_add_handle()函数的作用是向curl批处理会话中添加单独的curl句柄资源。curl_multi_add_handle()函数有两个参数,第一个参数表示一个curl批处理句柄资源,第二个参数表示一个单独的curl句柄资源。
curl_multi_exec()函数的作用是解析一个curl批处理句柄,curl_multi_exec()函数有两个参数,第一个参数表示一个批处理句柄资源,第二个参数是一个引用值的参数,表示剩余需要处理的单个的curl句柄资源数量。
curl_multi_remove_handle()函数表示移除curl批处理句柄资源中的某个句柄资源,curl_multi_remove_handle()函数有两个参数,第一个参数表示一个curl批处理句柄资源,第二个参数表示一个单独的curl句柄资源。
curl_multi_close()函数的作用是关闭一个批处理句柄资源。

$ch1 = curl_init(); $ch2 = curl_init(); curl_setopt($ch1, CURLOPT_URL, "http://www.baidu.com/"); curl_setopt($ch1, CURLOPT_HEADER, 0); curl_setopt($ch2, CURLOPT_URL, "http://www.google.com/"); curl_setopt($ch2, CURLOPT_HEADER, 0); $mh = curl_multi_init(); curl_multi_add_handle($mh,$ch1); curl_multi_add_handle($mh,$ch2); do { curl_multi_exec($mh,$flag); } while ($flag > 0); curl_multi_remove_handle($mh,$ch1); curl_multi_remove_handle($mh,$ch2); curl_multi_close($mh);


curl_multi_getcontent()函数的作用是在设置了CURLOPT_RETURNTRANSFER的情况下,返回获取的输出的文本流。
curl_multi_info_read()函数的作用是获取当前解析的curl的相关传输信息。
curl_multi_select()
Get all the sockets associated with the cURL extension, which can then be "selected"

以上就介绍了PHP CURL curl_setopt 参数,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Statement:
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