<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >curl_setopt</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="CURL, Client URL Library Functions" HREF="ref.curl.html"><LINK REL="PREVIOUS" TITLE="curl_setopt_array" HREF="function.curl-setopt-array.html"><LINK REL="NEXT" TITLE="curl_version" HREF="function.curl-version.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.curl-setopt-array.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.curl-version.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.curl-setopt" ></A >curl_setopt</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN26572" ></A ><P > (PHP 4 >= 4.0.2, PHP 5)</P >curl_setopt -- Set an option for a cURL transfer</DIV ><DIV CLASS="refsect1" ><A NAME="AEN26575" ></A ><H2 >说明</H2 >bool <B CLASS="methodname" >curl_setopt</B > ( resource ch, int option, mixed value )<BR ></BR ><P > Sets an option on the given cURL session handle. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN26590" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >ch</CODE ></DT ><DD ><P >A cURL handle returned by <A HREF="function.curl-init.html" ><B CLASS="function" >curl_init()</B ></A >.</P ></DD ><DT ><CODE CLASS="parameter" >option</CODE ></DT ><DD ><P > The <TT CLASS="literal" >CURLOPT_XXX</TT > option that you want to set </P ></DD ><DT ><CODE CLASS="parameter" >value</CODE ></DT ><DD ><P > The value to be set on <CODE CLASS="parameter" >option</CODE >. </P ><P > <CODE CLASS="parameter" >value</CODE > should be a bool for the following values of the <CODE CLASS="parameter" >option</CODE > parameter: <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN26615" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><THEAD ><TR ><TH >Option</TH ><TH >Set <CODE CLASS="parameter" >value</CODE > to</TH ><TH >Notes</TH ></TR ></THEAD ><TBODY ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_AUTOREFERER</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to automatically set the <TT CLASS="literal" >Referer:</TT > field in requests where it follows a <TT CLASS="literal" >Location:</TT > redirect. </TD ><TD > Available since PHP 5.1.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_BINARYTRANSFER</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to return the raw output when <TT CLASS="constant" ><B >CURLOPT_RETURNTRANSFER</B ></TT > is used. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_COOKIESESSION</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to mark this as a new cookie "session". It will force libcurl to ignore all cookies it is about to load that are "session cookies" from the previous session. By default, libcurl always stores and loads all cookies, independent if they are session cookies are not. Session cookies are cookies without expiry date and they are meant to be alive and existing for this "session" only. </TD ><TD > Available since PHP 5.1.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_CRLF</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to convert Unix newlines to CRLF newlines on transfers. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_DNS_USE_GLOBAL_CACHE</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to use a global DNS cache. This option is not thread-safe and is enabled by default. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FAILONERROR</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to fail silently if the HTTP code returned is greater than or equal to 400. The default behavior is to return the page normally, ignoring the code. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FILETIME</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to attempt to retrieve the modification date of the remote document. You can then retrieve this value using the <CODE CLASS="parameter" >CURLINFO_FILETIME</CODE > option with <A HREF="function.curl-getinfo.html" ><B CLASS="function" >curl_getinfo()</B ></A >. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FOLLOWLOCATION</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to follow any <TT CLASS="literal" >"Location: "</TT > header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many <TT CLASS="literal" >"Location: "</TT > headers that it is sent, unless <TT CLASS="constant" ><B >CURLOPT_MAXREDIRS</B ></TT > is set). </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FORBID_REUSE</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to force the connection to explicitly close when it has finished processing, and not be pooled for reuse. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FRESH_CONNECT</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to force the use of a new connection instead of a cached one. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FTP_USE_EPRT</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to use EPRT (and LPRT) when doing active FTP downloads. Use <TT CLASS="constant" ><B >FALSE</B ></TT > to disable EPRT and LPRT and use PORT only. </TD ><TD > Added in PHP 5.0.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FTP_USE_EPSV</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to first try an EPSV command for FTP transfers before reverting back to PASV. Set to <TT CLASS="constant" ><B >FALSE</B ></TT > to disable EPSV. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FTPAPPEND</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to append to the remote file instead of overwriting it. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FTPASCII</B ></TT ></TD ><TD > An alias of <TT CLASS="constant" ><B >CURLOPT_TRANSFERTEXT</B ></TT >. Use that instead. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FTPLISTONLY</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to only list the names of an FTP directory. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_HEADER</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to include the header in the output. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_HTTPGET</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to reset the HTTP request method to GET. Since GET is the default, this is only necessary if the request method has been changed. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_HTTPPROXYTUNNEL</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to tunnel through a given HTTP proxy. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_MUTE</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to be completely silent with regards to the cURL functions. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_NETRC</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to scan your <TT CLASS="filename" >~/.netrc</TT > file to find your username and password for the remote site that you're establishing a connection with. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_NOBODY</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to exclude the body from the output. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_NOPROGRESS</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to disable the progress meter for cURL transfers. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > PHP automatically sets this option to <TT CLASS="constant" ><B >TRUE</B ></TT >, this should only be changed for debugging purposes. </P ></BLOCKQUOTE ></DIV > </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_NOSIGNAL</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to ignore any cURL function that causes a signal to be sent to the PHP process. This is turned on by default in multi-threaded SAPIs so timeout options can still be used. </TD ><TD > Added in cURL 7.10 and PHP 5.0.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_POST</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to do a regular HTTP POST. This POST is the normal <TT CLASS="literal" >application/x-www-form-urlencoded</TT > kind, most commonly used by HTML forms. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_PUT</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to HTTP PUT a file. The file to PUT must be set with <TT CLASS="constant" ><B >CURLOPT_INFILE</B ></TT > and <TT CLASS="constant" ><B >CURLOPT_INFILESIZE</B ></TT >. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_RETURNTRANSFER</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to return the transfer as a string of the return value of <A HREF="function.curl-exec.html" ><B CLASS="function" >curl_exec()</B ></A > instead of outputting it out directly. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_SSL_VERIFYPEER</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >FALSE</B ></TT > to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the <TT CLASS="constant" ><B >CURLOPT_CAINFO</B ></TT > option or a certificate directory can be specified with the <TT CLASS="constant" ><B >CURLOPT_CAPATH</B ></TT > option. <TT CLASS="constant" ><B >CURLOPT_SSL_VERIFYHOST</B ></TT > may also need to be <TT CLASS="constant" ><B >TRUE</B ></TT > or <TT CLASS="constant" ><B >FALSE</B ></TT > if <TT CLASS="constant" ><B >CURLOPT_SSL_VERIFYPEER</B ></TT > is disabled (it defaults to 2). </TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > by default as of cURL 7.10. Default bundle installed as of cURL 7.10. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_TRANSFERTEXT</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to use ASCII mode for FTP transfers. For LDAP, it retrieves data in plain text instead of HTML. On Windows systems, it will not set <TT CLASS="literal" >STDOUT</TT > to binary mode. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_UNRESTRICTED_AUTH</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to keep sending the username and password when following locations (using <TT CLASS="constant" ><B >CURLOPT_FOLLOWLOCATION</B ></TT >), even when the hostname has changed. </TD ><TD > Added in PHP 5.0.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_UPLOAD</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to prepare for an upload. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_VERBOSE</B ></TT ></TD ><TD > <TT CLASS="constant" ><B >TRUE</B ></TT > to output verbose information. Writes output to <TT CLASS="literal" >STDERR</TT >, or the file specified using <TT CLASS="constant" ><B >CURLOPT_STDERR</B ></TT >. </TD ><TD > </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ><P > <CODE CLASS="parameter" >value</CODE > should be an integer for the following values of the <CODE CLASS="parameter" >option</CODE > parameter: <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN26842" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><THEAD ><TR ><TH >Option</TH ><TH >Set <CODE CLASS="parameter" >value</CODE > to</TH ><TH >Notes</TH ></TR ></THEAD ><TBODY ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_BUFFERSIZE</B ></TT ></TD ><TD > The size of the buffer to use for each read. There is no guarantee this request will be fulfilled, however. </TD ><TD > Added in cURL 7.10 and PHP 5.0.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_CLOSEPOLICY</B ></TT ></TD ><TD > Either <CODE CLASS="parameter" >CURLCLOSEPOLICY_LEAST_RECENTLY_USED</CODE > or <CODE CLASS="parameter" >CURLCLOSEPOLICY_OLDEST</CODE >. There are three other <TT CLASS="literal" >CURLCLOSEPOLICY_</TT > constants, but cURL does not support them yet. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_CONNECTTIMEOUT</B ></TT ></TD ><TD > The number of seconds to wait whilst trying to connect. Use 0 to wait indefinitely. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_DNS_CACHE_TIMEOUT</B ></TT ></TD ><TD > The number of seconds to keep DNS entries in memory. This option is set to 120 (2 minutes) by default. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FTPSSLAUTH</B ></TT ></TD ><TD > The FTP authentication method (when is activated): <TT CLASS="literal" >CURLFTPAUTH_SSL</TT > (try SSL first), <TT CLASS="literal" >CURLFTPAUTH_TLS</TT > (try TLS first), or <TT CLASS="literal" >CURLFTPAUTH_DEFAULT</TT > (let cURL decide). </TD ><TD > Added in cURL 7.12.2 and PHP 5.1.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_HTTP_VERSION</B ></TT ></TD ><TD > <CODE CLASS="parameter" >CURL_HTTP_VERSION_NONE</CODE > (default, lets CURL decide which version to use), <CODE CLASS="parameter" >CURL_HTTP_VERSION_1_0</CODE > (forces HTTP/1.0), or <CODE CLASS="parameter" >CURL_HTTP_VERSION_1_1</CODE > (forces HTTP/1.1). </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_HTTPAUTH</B ></TT ></TD ><TD > <P > The HTTP authentication method(s) to use. The options are: <CODE CLASS="parameter" >CURLAUTH_BASIC</CODE >, <CODE CLASS="parameter" >CURLAUTH_DIGEST</CODE >, <CODE CLASS="parameter" >CURLAUTH_GSSNEGOTIATE</CODE >, <CODE CLASS="parameter" >CURLAUTH_NTLM</CODE >, <CODE CLASS="parameter" >CURLAUTH_ANY</CODE >, and <CODE CLASS="parameter" >CURLAUTH_ANYSAFE</CODE >. </P > <P > You can use the bitwise <TT CLASS="literal" >|</TT > (or) operator to combine more than one method. If you do this, cURL will poll the server to see what methods it supports and pick the best one. </P > <P > <CODE CLASS="parameter" >CURLAUTH_ANY</CODE > is an alias for <TT CLASS="literal" >CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM</TT >. </P > <P > <CODE CLASS="parameter" >CURLAUTH_ANYSAFE</CODE > is an alias for <TT CLASS="literal" >CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM</TT >. </P > </TD ><TD > Added in PHP 5.0.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_INFILESIZE</B ></TT ></TD ><TD > The expected size, in bytes, of the file when uploading a file to a remote site. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_LOW_SPEED_LIMIT</B ></TT ></TD ><TD > The transfer speed, in bytes per second, that the transfer should be below during <TT CLASS="constant" ><B >CURLOPT_LOW_SPEED_TIME</B ></TT > seconds for PHP to consider the transfer too slow and abort. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_LOW_SPEED_TIME</B ></TT ></TD ><TD > The number of seconds the transfer should be below <TT CLASS="constant" ><B >CURLOPT_LOW_SPEED_LIMIT</B ></TT > for PHP to consider the transfer too slow and abort. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_MAXCONNECTS</B ></TT ></TD ><TD > The maximum amount of persistent connections that are allowed. When the limit is reached, <TT CLASS="constant" ><B >CURLOPT_CLOSEPOLICY</B ></TT > is used to determine which connection to close. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_MAXREDIRS</B ></TT ></TD ><TD > The maximum amount of HTTP redirections to follow. Use this option alongside <TT CLASS="constant" ><B >CURLOPT_FOLLOWLOCATION</B ></TT >. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_PORT</B ></TT ></TD ><TD > An alternative port number to connect to. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_PROXYAUTH</B ></TT ></TD ><TD > The HTTP authentication method(s) to use for the proxy connection. Use the same bitmasks as described in <TT CLASS="constant" ><B >CURLOPT_HTTPAUTH</B ></TT >. For proxy authentication, only <CODE CLASS="parameter" >CURLAUTH_BASIC</CODE > and <CODE CLASS="parameter" >CURLAUTH_NTLM</CODE > are currently supported. </TD ><TD > Added in cURL 7.10.7 and PHP 5.1.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_PROXYPORT</B ></TT ></TD ><TD > The port number of the proxy to connect to. This port number can also be set in <TT CLASS="constant" ><B >CURLOPT_PROXY</B ></TT >. </TD ><TD > Added in PHP 5.0.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_PROXYTYPE</B ></TT ></TD ><TD > Either <CODE CLASS="parameter" >CURLPROXY_HTTP</CODE > (default) or <CODE CLASS="parameter" >CURLPROXY_SOCKS5</CODE >. </TD ><TD > Added in cURL 7.10 and PHP 5.0.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_RESUME_FROM</B ></TT ></TD ><TD > The offset, in bytes, to resume a transfer from. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_SSL_VERIFYHOST</B ></TT ></TD ><TD > 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. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_SSLVERSION</B ></TT ></TD ><TD > The SSL version (2 or 3) to use. By default PHP will try to determine this itself, although in some cases you must set this manually. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_TIMECONDITION</B ></TT ></TD ><TD > How <TT CLASS="constant" ><B >CURLOPT_TIMEVALUE</B ></TT > is treated. Use <CODE CLASS="parameter" >CURL_TIMECOND_IFMODSINCE</CODE > to return the page only if it has been modified since the time specified in <TT CLASS="constant" ><B >CURLOPT_TIMEVALUE</B ></TT >. If it hasn't been modified, a <TT CLASS="literal" >"304 Not Modified"</TT > header will be returned assuming <TT CLASS="constant" ><B >CURLOPT_HEADER</B ></TT > is <TT CLASS="constant" ><B >TRUE</B ></TT >. Use <CODE CLASS="parameter" >CURL_TIMECOND_ISUNMODSINCE</CODE > for the reverse effect. <CODE CLASS="parameter" >CURL_TIMECOND_IFMODSINCE</CODE > is the default. </TD ><TD > Added in PHP 5.1.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_TIMEOUT</B ></TT ></TD ><TD > The maximum number of seconds to allow cURL functions to execute. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_TIMEVALUE</B ></TT ></TD ><TD > The time in seconds since January 1st, 1970. The time will be used by <TT CLASS="constant" ><B >CURLOPT_TIMECONDITION</B ></TT >. By default, <CODE CLASS="parameter" >CURL_TIMECOND_IFMODSINCE</CODE > is used. </TD ><TD > </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ><P > <CODE CLASS="parameter" >value</CODE > should be a string for the following values of the <CODE CLASS="parameter" >option</CODE > parameter: <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN27008" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><THEAD ><TR ><TH >Option</TH ><TH >Set <CODE CLASS="parameter" >value</CODE > to</TH ><TH >Notes</TH ></TR ></THEAD ><TBODY ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_CAINFO</B ></TT ></TD ><TD > The name of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with <TT CLASS="constant" ><B >CURLOPT_SSL_VERIFYPEER</B ></TT >. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_CAPATH</B ></TT ></TD ><TD > A directory that holds multiple CA certificates. Use this option alongside <TT CLASS="constant" ><B >CURLOPT_SSL_VERIFYPEER</B ></TT >. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_COOKIE</B ></TT ></TD ><TD > The contents of the <TT CLASS="literal" >"Set-Cookie: "</TT > header to be used in the HTTP request. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_COOKIEFILE</B ></TT ></TD ><TD > The name of the file containing the cookie data. The cookie file can be in Netscape format, or just plain HTTP-style headers dumped into a file. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_COOKIEJAR</B ></TT ></TD ><TD > The name of a file to save all internal cookies to when the connection closes. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_CUSTOMREQUEST</B ></TT ></TD ><TD > A custom request method to use instead of <TT CLASS="literal" >"GET"</TT > or <TT CLASS="literal" >"HEAD"</TT > when doing a HTTP request. This is useful for doing <TT CLASS="literal" >"DELETE"</TT > or other, more obscure HTTP requests. Valid values are things like <TT CLASS="literal" >"GET"</TT >, <TT CLASS="literal" >"POST"</TT >, <TT CLASS="literal" >"CONNECT"</TT > and so on; i.e. Do not enter a whole HTTP request line here. For instance, entering <TT CLASS="literal" >"GET /index.html HTTP/1.0\r\n\r\n"</TT > would be incorrect. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > Don't do this without making sure your server supports the custom request method first. </P ></BLOCKQUOTE ></DIV > </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_EGBSOCKET</B ></TT ></TD ><TD > Like <TT CLASS="constant" ><B >CURLOPT_RANDOM_FILE</B ></TT >, except a filename to an Entropy Gathering Daemon socket. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_ENCODING</B ></TT ></TD ><TD > The contents of the <TT CLASS="literal" >"Accept-Encoding: "</TT > header. This enables decoding of the response. Supported encodings are <TT CLASS="literal" >"identity"</TT >, <TT CLASS="literal" >"deflate"</TT >, and <TT CLASS="literal" >"gzip"</TT >. If an empty string, <TT CLASS="literal" >""</TT >, is set, a header containing all supported encoding types is sent. </TD ><TD > Added in cURL 7.10. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FTPPORT</B ></TT ></TD ><TD > 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. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_INTERFACE</B ></TT ></TD ><TD > The name of the outgoing network interface to use. This can be an interface name, an IP address or a host name. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_KRB4LEVEL</B ></TT ></TD ><TD > The KRB4 (Kerberos 4) security level. Any of the following values (in order from least to most powerful) are valid: <TT CLASS="literal" >"clear"</TT >, <TT CLASS="literal" >"safe"</TT >, <TT CLASS="literal" >"confidential"</TT >, <TT CLASS="literal" >"private".</TT >. If the string does not match one of these, <TT CLASS="literal" >"private"</TT > is used. Setting this option to <TT CLASS="constant" ><B >NULL</B ></TT > will disable KRB4 security. Currently KRB4 security only works with FTP transactions. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_POSTFIELDS</B ></TT ></TD ><TD > The full data to post in a HTTP "POST" operation. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_PROXY</B ></TT ></TD ><TD > The HTTP proxy to tunnel requests through. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_PROXYUSERPWD</B ></TT ></TD ><TD > A username and password formatted as <TT CLASS="literal" >"[username]:[password]"</TT > to use for the connection to the proxy. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_RANDOM_FILE</B ></TT ></TD ><TD > A filename to be used to seed the random number generator for SSL. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_RANGE</B ></TT ></TD ><TD > Range(s) of data to retrieve in the format <TT CLASS="literal" >"X-Y"</TT > where X or Y are optional. HTTP transfers also support several intervals, separated with commas in the format <TT CLASS="literal" >"X-Y,N-M"</TT >. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_REFERER</B ></TT ></TD ><TD > The contents of the <TT CLASS="literal" >"Referer: "</TT > header to be used in a HTTP request. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_SSL_CIPHER_LIST</B ></TT ></TD ><TD > A list of ciphers to use for SSL. For example, <TT CLASS="literal" >RC4-SHA</TT > and <TT CLASS="literal" >TLSv1</TT > are valid cipher lists. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_SSLCERT</B ></TT ></TD ><TD > The name of a file containing a PEM formatted certificate. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_SSLCERTPASSWD</B ></TT ></TD ><TD > The password required to use the <TT CLASS="constant" ><B >CURLOPT_SSLCERT</B ></TT > certificate. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_SSLCERTTYPE</B ></TT ></TD ><TD > The format of the certificate. Supported formats are <TT CLASS="literal" >"PEM"</TT > (default), <TT CLASS="literal" >"DER"</TT >, and <TT CLASS="literal" >"ENG"</TT >. </TD ><TD > Added in cURL 7.9.3 and PHP 5.0.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_SSLENGINE</B ></TT ></TD ><TD > The identifier for the crypto engine of the private SSL key specified in <TT CLASS="constant" ><B >CURLOPT_SSLKEY</B ></TT >. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_SSLENGINE_DEFAULT</B ></TT ></TD ><TD > The identifier for the crypto engine used for asymmetric crypto operations. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_SSLKEY</B ></TT ></TD ><TD > The name of a file containing a private SSL key. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_SSLKEYPASSWD</B ></TT ></TD ><TD > The secret password needed to use the private SSL key specified in <TT CLASS="constant" ><B >CURLOPT_SSLKEY</B ></TT >. <DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > Since this option contains a sensitive password, remember to keep the PHP script it is contained within safe. </P ></BLOCKQUOTE ></DIV > </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_SSLKEYTYPE</B ></TT ></TD ><TD > The key type of the private SSL key specified in <TT CLASS="constant" ><B >CURLOPT_SSLKEY</B ></TT >. Supported key types are <TT CLASS="literal" >"PEM"</TT > (default), <TT CLASS="literal" >"DER"</TT >, and <TT CLASS="literal" >"ENG"</TT >. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_URL</B ></TT ></TD ><TD > The URL to fetch. You can also set this when initializing a session with <A HREF="function.curl-init.html" ><B CLASS="function" >curl_init()</B ></A >. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_USERAGENT</B ></TT ></TD ><TD > The contents of the <TT CLASS="literal" >"User-Agent: "</TT > header to be used in a HTTP request. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_USERPWD</B ></TT ></TD ><TD > A username and password formatted as <TT CLASS="literal" >"[username]:[password]"</TT > to use for the connection. </TD ><TD > </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ><P > <CODE CLASS="parameter" >value</CODE > should be an array for the following values of the <CODE CLASS="parameter" >option</CODE > parameter: <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN27210" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><THEAD ><TR ><TH >Option</TH ><TH >Set <CODE CLASS="parameter" >value</CODE > to</TH ><TH >Notes</TH ></TR ></THEAD ><TBODY ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_HTTP200ALIASES</B ></TT ></TD ><TD > An array of HTTP 200 responses that will be treated as valid responses and not as errors. </TD ><TD > Added in cURL 7.10.3 and PHP 5.0.0. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_HTTPHEADER</B ></TT ></TD ><TD > An array of HTTP header fields to set. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_POSTQUOTE</B ></TT ></TD ><TD > An array of FTP commands to execute on the server after the FTP request has been performed. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_QUOTE</B ></TT ></TD ><TD > An array of FTP commands to execute on the server prior to the FTP request. </TD ><TD > </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ><P > <CODE CLASS="parameter" >value</CODE > should be a stream resource (using <A HREF="function.fopen.html" ><B CLASS="function" >fopen()</B ></A >, for example) for the following values of the <CODE CLASS="parameter" >option</CODE > parameter: <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN27243" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><THEAD ><TR ><TH >Option</TH ><TH >Set <CODE CLASS="parameter" >value</CODE > to</TH ><TH >Notes</TH ></TR ></THEAD ><TBODY ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_FILE</B ></TT ></TD ><TD > The file that the transfer should be written to. The default is <TT CLASS="literal" >STDOUT</TT > (the browser window). </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_INFILE</B ></TT ></TD ><TD > The file that the transfer should be read from when uploading. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_STDERR</B ></TT ></TD ><TD > An alternative location to output errors to instead of <TT CLASS="literal" >STDERR</TT >. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_WRITEHEADER</B ></TT ></TD ><TD > The file that the header part of the transfer is written to. </TD ><TD > </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ><P > <CODE CLASS="parameter" >value</CODE > should be a string that is the name of a valid callback function for the following values of the <CODE CLASS="parameter" >option</CODE > parameter: <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN27277" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><COL><THEAD ><TR ><TH >Option</TH ><TH >Set <CODE CLASS="parameter" >value</CODE > to</TH ><TH >Notes</TH ></TR ></THEAD ><TBODY ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_HEADERFUNCTION</B ></TT ></TD ><TD > The name of a callback function where the callback function takes two parameters. The first is the cURL resource, the second is a string with the header data to be written. Using this callback function, it becomes your responsibility to write the header data. Return the number of bytes written. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_PASSWDFUNCTION</B ></TT ></TD ><TD > The name of a callback function where the callback function takes three parameters. The first is the cURL resource, the second is a string containing a password prompt, and the third is the maximum password length. Return the string containing the password. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_READFUNCTION</B ></TT ></TD ><TD > The name of a callback function where the callback function takes two parameters. The first is the cURL resource, and the second is a string with the data to be read. Using this callback function, it becomes your responsibility to read the data. Return the number of bytes read. Return 0 to signal <TT CLASS="literal" >EOF</TT >. </TD ><TD > </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >CURLOPT_WRITEFUNCTION</B ></TT ></TD ><TD > The name of a callback function where the callback function takes two parameters. The first is the cURL resource, and the second is a string with the data to be written. Using this callback function, it becomes your responsibility to write the data. Must return the exact number of bytes written or this will fail. </TD ><TD > </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN27307" ></A ><H2 >返回值</H2 ><P > 如果成功则返回 <TT CLASS="constant" ><B >TRUE</B ></TT >,失败则返回 <TT CLASS="constant" ><B >FALSE</B ></TT >。 </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN27312" ></A ><H2 >范例</H2 ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN27315" ></A ><P ><B >例 1. Initializing a new cURL session and fetching a web page </B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">// create a new cURL resource<br /></font><font color="#0000BB">$ch </font><font color="#007700">= </font><font color="#0000BB">curl_init</font><font color="#007700">();<br /><br /></font><font color="#FF8000">// set URL and other appropriate options<br /></font><font color="#0000BB">curl_setopt</font><font color="#007700">(</font><font color="#0000BB">$ch</font><font color="#007700">, </font><font color="#0000BB">CURLOPT_URL</font><font color="#007700">, </font><font color="#DD0000">"http://www.example.com/"</font><font color="#007700">);<br /></font><font color="#0000BB">curl_setopt</font><font color="#007700">(</font><font color="#0000BB">$ch</font><font color="#007700">, </font><font color="#0000BB">CURLOPT_HEADER</font><font color="#007700">, </font><font color="#0000BB">false</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// grab URL and pass it to the browser<br /></font><font color="#0000BB">curl_exec</font><font color="#007700">(</font><font color="#0000BB">$ch</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// close cURL resource, and free up system resources<br /></font><font color="#0000BB">curl_close</font><font color="#007700">(</font><font color="#0000BB">$ch</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN27318" ></A ><H2 >参见</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.curl-setopt-array.html" ><B CLASS="function" >curl_setopt_array()</B ></A ></TD ></TR ></TBODY ></TABLE ><P ></P > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.curl-setopt-array.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.curl-version.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >curl_setopt_array</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.curl.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >curl_version</TD ></TR ></TABLE ></DIV ></BODY ></HTML >