


Introduction to the concept and usage examples of php curl_setopt function
php What does the curl_setopt function do?
The curl_setopt function is an important function in php. It is used to set a cURL transmission option. So how is it set up? What are the parameters? The main purpose of this article is to give you a detailed introduction to the curl_setopt function in php.
First look at the syntax descriptionbool curl_setopt ( resource $ch , int $option , mixed $value )
ch
By The cURL handle returned by curl_init().
optionCURLOPT_XXX options that need to be set. value
The value that will be set on the option option.PS: Note here that the value is set according to the parameters selected by the option, as follows
For the optional parameters of the following options, value should be set to a bool type value:
Options | OptionalvalueValue | Remarks | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CURLOPT_AUTOREFERER | When redirected according to Location:, the Referer: information in the header is automatically set. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##CURLOPT_BINARYTRANSFER | WhenCURLOPT_RETURNTRANSFER is enabled, return the native ( Raw) output. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
When enabled, curl will only pass one session cookie and ignore other cookies. By 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. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
When enabled, convert Unix line feeds into carriage returns and line feeds. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
When enabled, a global DNS cache will be enabled. This item is thread-safe. , and is enabled by default. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Display HTTP status code, the default behavior is to ignore HTTP information with a number less than or equal to 400 . | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
When enabled, an attempt will be made to modify information in the remote document. The result information will be returned through the CURLINFO_FILETIME | option of the curl_getinfo() function. curl_getinfo().|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
When enabled, the server will return the " Location: " | Put it in the header and return it to the server recursively. UseCURLOPT_MAXREDIRS to limit the number of recursive returns. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Forcibly disconnects after completing the interaction and cannot be reused. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Force to obtain a new connection to replace the one in the cache. | ##CURLOPT_FTP_USE_EPRT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FALSE disables EPRT and LPRT, use the PORT command only. | ##CURLOPT_FTP_USE_EPSV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
. | CURLOPT_FTPAPPEND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##CURLOPT_FTPASCII | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##CURLOPT_FTPLISTONLY | When enabled, only the name of the FTP directory is listed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CURLOPT_HEADER | When enabled, the header file information will be output as a data stream. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CURLINFO_HEADER_OUT | The request string for the tracking handle when enabled. | Available starting with PHP 5.1.3. ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 | When enabled, all modified parameters in the cURL function will be restored to their default values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CURLOPT_NETRC | After the connection is established, access the 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 | Close the progress bar of curl transmission when enabled, the default for this item Set to enabled.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CURLOPT_NOSIGNAL | When enabled, ignore all curl passed to php signal of. This item is enabled by default during SAPI multi-threaded transmission.cURL was added in 7.10. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CURLOPT_POST | When enabled, a regular POST request will be sent, the type is:application/x-www-form-urlencoded , just like form submission. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Allows HTTP to send files when enabled. | CURLOPT_INFILE## must be set at the same time. # andCURLOPT_INFILESIZE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Return the information obtained by curl_exec() in the form of a file stream instead of Direct output. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
After disabling cURL will terminate verification from the server. Use the CURLOPT_CAINFO option to set the certificate. Use the | CURLOPT_CAPATHoption to set the certificate directory. If CURLOPT_SSL_VERIFYPEER (default value is 2) is enabled, CURLOPT_SSL_VERIFYHOST needs to be set to TRUE otherwise set to FALSE. Defaults to TRUE since cURL 7.10. Starting with cURL 7.10, bundle installation is defaulted. | CURLOPT_TRANSFERTEXT | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Use ASCII mode for FTP transfers when enabled. For LDAP, it retrieves plain text information rather than HTML. On Windows systems, the system does not set STDOUT to binary mode. | ##CURLOPT_UNRESTRICTED_AUTH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CURLOPT_FOLLOWLOCATION Username and password information continues to be appended to locations, even if the domain name has changed. | CURLOPT_UPLOAD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##CURLOPT_VERBOSE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
or the specified CURLOPT_STDERR. |
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.||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The time to wait before initiating a connection. If set to 0, it will wait indefinitely . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set the time to save DNS information in memory, the default is 120 seconds. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##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 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 many protocols, but only to use 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 _TFTP,CURLPROTO_ALL||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CURLOPT_PROTOCOLSCURLPROTO_* | refers to the bit field. 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. SeeCURLOPT_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 _TFTP,CURLPROTO_ALL|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CURLOPT_PROXYAUTHVerification method for HTTP proxy connection. Use the bitfield flags in CURLOPT_HTTPAUTH | to set the corresponding options. For proxy authentication onlyCURLAUTH_BASIC | and|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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).||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
If after a certain time specified by CURLOPT_TIMEVALUE | If it has been edited, useCURL_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. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set the maximum number of seconds cURL is allowed to execute. | ##CURLOPT_TIMEOUT_MS | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
was added in cURL 7.16.2. Available from PHP 5.2.3 onwards. | ##CURLOPT_TIMEVALUE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
. By default, CURL_TIMECOND_IFMODSINCE is used . |
Options | OptionalvalueValue | Remarks |
---|---|---|
CURLOPT_CAINFO | A file name that holds one or more certificates for server verification. 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"). | |
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. | ||
A file that saves cookie information after the connection is completed. | ||
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: | |
##CURLOPT_EGDSOCKET | Similar toCURLOPT_RANDOM_FILE, except for an Entropy Gathering Daemon socket. | |
"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. | |
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. | ||
The network sending interface name can be an interface name, IP address or a CPU name. | ||
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 certification can only be used for FTP transfers. | |
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. | |
HTTP proxy channel. | ##CURLOPT_PROXYUSERPWD | |
"[username]:[ password]" format string. | ##CURLOPT_RANDOM_FILE | |
##CURLOPT_RANGE | ||
"X-Y,N-M". | ##CURLOPT_REFERER | In the HTTP request header | "Referer: "
CURLOPT_SSL_CIPHER_LIST | A list of SSL encryption algorithms. For example, | RC4-SHA|
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.
| |
CURLOPT_SSLKEY | The encryption type of the private key. The supported key types are "PEM" (default value), "DER" and "ENG". | |
The URL address that needs to be obtained can also be obtained in curl_init() | Set in function.||
Include a "User-Agent: "# in the HTTP request ##Header string. | ##CURLOPT_USERPWD | |
. |
#For the following options Optional parameters, value should be set to an array:
optionsoptional
value##CURLOPT_HTTP200ALIASES | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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. | |||||||||||||||||||||
对于下面的这些option的可选参数,value应该被设置一个流资源 (例如使用fopen()):
对于下面的这些option的可选参数,value应该被设置为一个回调函数名:
返回值 成功时返回 TRUE, 或者在失败时返回 FALSE。 实例 初始化一个新的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); ?> Copy after login 上传文件实例: <?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); ?> Copy after login 以上实例输出结果如下: 注释 传递一个数组到CURLOPT_POSTFIELDS,cURL会把数据编码成 multipart/form-data,而然传递一个URL-encoded字符串时,数据会被编码成 application/x-www-form-urlencoded。 【相关文章推荐】 The above is the detailed content of Introduction to the concept and usage examples of php curl_setopt function. For more information, please follow other related articles on the PHP Chinese website! Statement of this Website
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
![]() Hot AI Tools![]() Undresser.AI UndressAI-powered app for creating realistic nude photos ![]() AI Clothes RemoverOnline AI tool for removing clothes from photos. ![]() Undress AI ToolUndress images for free ![]() Clothoff.ioAI clothes remover ![]() Video Face SwapSwap faces in any video effortlessly with our completely free AI face swap tool! ![]() Hot Article
Roblox: Grow A Garden - Complete Mutation Guide
3 weeks ago
By DDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How to fix KB5055612 fails to install in Windows 10?
3 weeks ago
By DDD
Nordhold: Fusion System, Explained
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
![]() Hot Tools![]() Notepad++7.3.1Easy-to-use and free code editor ![]() SublimeText3 Chinese versionChinese version, very easy to use ![]() Zend Studio 13.0.1Powerful PHP integrated development environment ![]() Dreamweaver CS6Visual web development tools ![]() SublimeText3 Mac versionGod-level code editing software (SublimeText3) ![]() Hot Topics
Java Tutorial
![]() ![]()
CakePHP Tutorial
![]() ![]()
Laravel Tutorial
![]() ![]()
PHP Tutorial
![]() ![]()
C# Tutorial
![]() ![]() ![]() PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners. ![]() PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7 ![]() PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved. ![]() PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries. ![]() PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers. ![]() PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development. ![]() PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning. ![]() PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning. ![]() |