function.curl-setopt.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 1,406 行 · 第 1/4 页
HTML
1,406 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Set an option for a cURL transfer</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.curl-setopt-array.html">curl_setopt_array</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.curl-version.html">curl_version</a></div> <div class="up"><a href="ref.curl.html">cURL Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.curl-setopt" class="refentry"> <div class="refnamediv"> <h1 class="refname">curl_setopt</h1> <p class="verinfo">(PHP 4 >= 4.0.2, PHP 5)</p><p class="refpurpose"><span class="refname">curl_setopt</span> — <span class="dc-title">Set an option for a cURL transfer</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><b><b>curl_setopt</b></b></span> ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$ch</tt></span> , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$option</tt></span> , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$value</tt></span> )</div> <p class="para rdfs-comment"> Sets an option on the given cURL session handle. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt><span class="term"><i><tt class="parameter">ch</tt></i></span><dd><p class="para">A cURL handle returned by <a href="function.curl-init.html" class="function">curl_init()</a>.</p></dd></dt> <dt> <span class="term"><i><tt class="parameter">option</tt></i></span> <dd> <p class="para"> The <i>CURLOPT_XXX</i> option to set. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">value</tt></i></span> <dd> <p class="para"> The value to be set on <i><tt class="parameter">option</tt></i>. </p> <p class="para"> <i><tt class="parameter">value</tt></i> should be a bool for the following values of the <i><tt class="parameter">option</tt></i> parameter: <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Option</th> <th colspan="1">Set <i><tt class="parameter">value</tt></i> to</th> <th colspan="1">Notes</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_AUTOREFERER</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to automatically set the <i>Referer:</i> field in requests where it follows a <i>Location:</i> redirect. </td> <td colspan="1" rowspan="1" align="left"> Available since PHP 5.1.0. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_BINARYTRANSFER</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to return the raw output when <b><tt>CURLOPT_RETURNTRANSFER</tt></b> is used. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_COOKIESESSION</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> 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 colspan="1" rowspan="1" align="left"> Available since PHP 5.1.0. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_CRLF</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to convert Unix newlines to CRLF newlines on transfers. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_DNS_USE_GLOBAL_CACHE</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to use a global DNS cache. This option is not thread-safe and is enabled by default. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_FAILONERROR</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> 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 colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_FILETIME</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to attempt to retrieve the modification date of the remote document. This value can be retrieved using the <i><tt class="parameter">CURLINFO_FILETIME</tt></i> option with <a href="function.curl-getinfo.html" class="function">curl_getinfo()</a>. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_FOLLOWLOCATION</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to follow any <i>"Location: "</i> header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many <i>"Location: "</i> headers that it is sent, unless <b><tt>CURLOPT_MAXREDIRS</tt></b> is set). </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_FORBID_REUSE</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to force the connection to explicitly close when it has finished processing, and not be pooled for reuse. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_FRESH_CONNECT</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to force the use of a new connection instead of a cached one. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_FTP_USE_EPRT</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to use EPRT (and LPRT) when doing active FTP downloads. Use <b><tt>FALSE</tt></b> to disable EPRT and LPRT and use PORT only. </td> <td colspan="1" rowspan="1" align="left"> Added in PHP 5.0.0. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_FTP_USE_EPSV</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to first try an EPSV command for FTP transfers before reverting back to PASV. Set to <b><tt>FALSE</tt></b> to disable EPSV. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_FTPAPPEND</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to append to the remote file instead of overwriting it. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_FTPASCII</tt></b></td> <td colspan="1" rowspan="1" align="left"> An alias of <b><tt>CURLOPT_TRANSFERTEXT</tt></b>. Use that instead. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_FTPLISTONLY</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to only list the names of an FTP directory. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_HEADER</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to include the header in the output. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_HTTPGET</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> 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 colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_HTTPPROXYTUNNEL</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to tunnel through a given HTTP proxy. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_MUTE</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to be completely silent with regards to the cURL functions. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_NETRC</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to scan the <var class="filename">~/.netrc</var> file to find a username and password for the remote site that a connection is being established with. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_NOBODY</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to exclude the body from the output. </td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_NOPROGRESS</tt></b></td> <td colspan="1" rowspan="1" align="left"><p class="para"> <b><tt>TRUE</tt></b> to disable the progress meter for cURL transfers. <blockquote><p><b class="note">Note</b>: PHP automatically sets this option to <b><tt>TRUE</tt></b>, this should only be changed for debugging purposes. <br /> </p></blockquote> </p></td> <td colspan="1" rowspan="1" align="left"> </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_NOSIGNAL</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> 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 colspan="1" rowspan="1" align="left"> Added in cURL 7.10 and PHP 5.0.0. </td> </tr> <tr valign="middle"> <td colspan="1" rowspan="1" align="left"><b><tt>CURLOPT_POST</tt></b></td> <td colspan="1" rowspan="1" align="left"> <b><tt>TRUE</tt></b> to do a regular HTTP POST. This POST is the normal <i>application/x-www-form-urlencoded</i> kind, most commonly used by HTML forms. </td> <td colspan="1" rowspan="1" align="left"> </td>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?