Home  >  Article  >  Backend Development  >  Chinese archives of curl function_PHP tutorial

Chinese archives of curl function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:36:43858browse

curl_setopt — 为CURL调用设置一个选项
描述

bool curl_setopt (int ch, string option, mixed value)

curl_setopt()函数将为一个CURL会话设置选项。option参数是你想要的设置,value是这个选项给定的值。

下列选项的值将被作为长整形使用(在option参数中指定): 

*CURLOPT_INFILESIZE: 当你上传一个文件到远程站点,这个选项告诉PHP你上传文件的大小。
*CURLOPT_VERBOSE: 如果你想CURL报告每一件意外的事情,设置这个选项为一个非零值。
*CURLOPT_HEADER: 如果你想把一个头包含在输出中,设置这个选项为一个非零值。
*CURLOPT_NOPROGRESS: 如果你不会PHP为CURL传输显示一个进程条,设置这个选项为一个非零值。

注意:PHP自动设置这个选项为非零值,你应该仅仅为了调试的目的来改变这个选项。

*CURLOPT_NOBODY: 如果你不想在输出中包含body部分,设置这个选项为一个非零值。
*CURLOPT_FAILONERROR: 如果你想让PHP在发生错误(HTTP代码返回大于等于300)时,不显示,设置这个选项为一人非零值。默认行为是返回一个正常页,忽略代码。
*CURLOPT_UPLOAD: 如果你想让PHP为上传做准备,设置这个选项为一个非零值。
*CURLOPT_POST: 如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
*CURLOPT_FTPLISTONLY: 设置这个选项为非零值,PHP将列出FTP的目录名列表。
*CURLOPT_FTPAPPEND: 设置这个选项为一个非零值,PHP将应用远程文件代替覆盖它。
*CURLOPT_NETRC: 设置这个选项为一个非零值,PHP将在你的 ~./netrc 文件中查找你要建立连接的远程站点的用户名及密码。
*CURLOPT_FOLLOWLOCATION: 设置这个选项为一个非零值(象 “Location: “)的头,服务器会把它当做HTTP头的一部分发送(注意这是递归的,PHP将发送形如 “Location: “的头)。
*CURLOPT_PUT: 设置这个选项为一个非零值去用HTTP上传一个文件。要上传这个文件必须设置CURLOPT_INFILE和CURLOPT_INFILESIZE选项.
*CURLOPT_MUTE: 设置这个选项为一个非零值,PHP对于CURL函数将完全沉默。
*CURLOPT_TIMEOUT: 设置一个长整形数,作为最大延续多少秒。
*CURLOPT_LOW_SPEED_LIMIT: 设置一个长整形数,控制传送多少字节。
*CURLOPT_LOW_SPEED_TIME: 设置一个长整形数,控制多少秒传送CURLOPT_LOW_SPEED_LIMIT规定的字节数。
*CURLOPT_RESUME_FROM: 传递一个包含字节偏移地址的长整形参数,(你想转移到的开始表单)。
*CURLOPT_SSLVERSION: 传递一个包含SSL版本的长参数。默认PHP将被它自己努力的确定,在更多的安全中你必须手工设置。
*CURLOPT_TIMECONDITION: 传递一个长参数,指定怎么处理CURLOPT_TIMEVALUE参数。你可以设置这个参数为TIMECOND_IFMODSINCE 或 TIMECOND_ISUNMODSINCE。这仅用于HTTP。
*CURLOPT_TIMEVALUE: 传递一个从1970-1-1开始到现在的秒数。这个时间将被CURLOPT_TIMEVALUE选项作为指定值使用,或被默认TIMECOND_IFMODSINCE使用。

下列选项的值将被作为字符串: 

*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: Do not do this before confirming that your server supports the command.

The following options require a file description (obtained by using the fopen() function):

*CURLOPT_FILE: This file will be the output file you place the transfer. The default is STDOUT.
*CURLOPT_INFILE: This file is the input file you sent.
*CURLOPT_WRITEHEADER: This file contains the header part of your output.
*CURLOPT_STDERR: This file has errors written instead of stderr.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486628.htmlTechArticlecurl_setopt — Set an option description for CURL call bool curl_setopt (int ch, string option, mixed value) curl_setopt() The function will set options for a CURL session. The option parameter is you...
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