curl_setopt
Set an option for a CURL transfer
Description
boolcurl_setopt
resourcech
stringoption
mixedvalue
The curl_setopt function will set options
for a CURL session identified by the ch
parameter. The option parameter is the
option you want to set, and the value is
the value of the option given by the
option.
The value should be a long for the
following options (specified in the option
parameter):
CURLOPT_INFILESIZE: When you are
uploading a file to a remote site, this option should be used
to tell PHP what the expected size of the infile will be.
CURLOPT_VERBOSE: Set this option to a
non-zero value if you want CURL to report everything that is
happening. Writes output to stderr, or the file specified
using CURLOPT_STDERR.
CURLOPT_HEADER: Set this option to a
non-zero value if you want the header to be included in the
output.
CURLOPT_NOPROGRESS: Set this option to
a non-zero value if you don't want PHP to display a progress
meter for CURL transfers.
PHP automatically sets this option to a non-zero parameter,
this should only be changed for debugging purposes.
CURLOPT_NOBODY: Set this option to a
non-zero value if you don't want the body included with the
output.
CURLOPT_FAILONERROR: Set this option to
a non-zero value if you want PHP to fail silently if the HTTP
code returned is greater than 300. The default behavior is
to return the page normally, ignoring the code.
CURLOPT_UPLOAD: Set this option to a
non-zero value if you want PHP to prepare for an upload.
CURLOPT_POST: Set this option to a
non-zero value if you want PHP to do a regular HTTP POST.
This POST is a normal application/x-www-form-urlencoded
kind, most commonly used by HTML forms.
CURLOPT_FTPLISTONLY: Set this option to
a non-zero value and PHP will just list the names of an FTP
directory.
CURLOPT_FTPAPPEND: Set this option to a
non-zero value and PHP will append to the remote file instead
of overwriting it.
CURLOPT_NETRC: Set this option to a
non-zero value and PHP will scan your ~./netrc
file to find your username and password for the remote site that
you're establishing a connection with.
CURLOPT_FOLLOWLOCATION: Set this option
to a non-zero value to follow any "Location: " header that the
server sends as a part of the HTTP header (note this is
recursive, PHP will follow as many "Location: " headers that
it is sent.)
CURLOPT_PUT: Set this option to a non-zero
value to HTTP PUT a file. The file to PUT must be set with
the CURLOPT_INFILE and
CURLOPT_INFILESIZE.
CURLOPT_MUTE: Set this option to a
non-zero value and PHP will be completely silent with regards
to the CURL functions.
CURLOPT_TIMEOUT: Pass a long as a
parameter that contains the maximum time, in seconds, that
you'll allow the CURL functions to take.
CURLOPT_LOW_SPEED_LIMIT: Pass a long as
a parameter that contains the transfer speed in bytes per
second that the transfer should be below during
CURLOPT_LOW_SPEED_TIME seconds for PHP to
consider too slow and abort.
CURLOPT_LOW_SPEED_TIME: Pass a long as
a parameter that contains the time in seconds that the
transfer should be below the
CURLOPT_LOW_SPEED_LIMIT for PHP
to consider it too slow and abort.
CURLOPT_RESUME_FROM: Pass a long as a
parameter that contains the offset, in bytes, that you want
the transfer to start from.
CURLOPT_CAINFO: Pass a filename of a file
holding one or more certificates to verify the peer with. This only
makes sense when used in combination with the
CURLOPT_SSL_VERIFYPEER option.
CURLOPT_SSL_VERIFYPEER: Pass a long that is set
to a zero value to stop curl from verifying the peer's certificate
(curl 7.10 starting setting this option to &true; by default).
Alternate certificates to verify against can be specified with the
CURLOPT_CAINFO option (added in curl 7.9.8)
or a certificate directory can be specified with the
CURLOPT_CAPATH option. As of curl 7.10, curl installs a
default bundle. CURLOPT_SSL_VERIFYHOST may
also need to be set to 1 or 0 if CURLOPT_SSL_VERIFYPEER
is disabled (it defaults to 2).
CURLOPT_SSLVERSION: Pass a long as a
parameter that contains the SSL version (2 or 3) to use. By
default PHP will try and determine this by itself, although,
in some cases you must set this manually.
CURLOPT_SSL_VERIFYHOST: Pass a long if
CURL should verify the Common name of the peer certificate in the
SSL handshake. A value of 1 denotes that we should check for the
existence of the common name, a value of 2 denotes that we should
make sure it matches the provided hostname.
CURLOPT_TIMECONDITION: Pass a long as a
parameter that defines how the
CURLOPT_TIMEVALUE is treated.
You can set this parameter to TIMECOND_IFMODSINCE or
TIMECOND_ISUNMODSINCE. This is a HTTP-only feature.
CURLOPT_TIMEVALUE: Pass a long as a
parameter that is the time in seconds since January 1st, 1970.
The time will be used as specified by the
CURLOPT_TIMECONDITION
option, or by default the TIMECOND_IFMODSINCE will be used.
CURLOPT_RETURNTRANSFER: Set this option to a
non-zero value if you want CURL to directly return the transfer
instead of printing it out directly.
CURLOPT_NOSIGNAL: Set this option to a non-zero
value if you want CURL 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. Added
in CURL 7.10.
CURLOPT_DNS_USE_GLOBAL_CACHE: Set this option
to a non-zero value if you want CURL to use a global DNS cache. This
option is not thread-safe and is turned on by default.
CURLOPT_DNS_CACHE_TIMEOUT: Pass a long as a
parameter that is the amount of seconds CURL should keep DNS entries
in memory. This option is set to 120 (2 minutes) by default.
CURLOPT_PORT: Pass a long as a
parameter specifying the port number to connect to, instead of the
default for the protocol used.
CURLOPT_TRANSFERTEXT: Set this option to a
non-zero value if you want CURL to use ASCII mode for FTP transfers.
For LDAP, it retrieves data in plain text instead of HTML. On Windows
systems, stdout will not be set to binary mode.
CURLOPT_FTPASCII: An alias of
CURLOPT_TRANSFERTEXT. Use that instead.
CURLOPT_FTP_USE_EPSV: Set this option to a
non-zero value if you want CURL to first try an EPSV command for FTP
transfers before reverting back to PASV. Set this option to zero to
disable EPSV.
CURLOPT_HTTPPROXYTUNNEL: Set this option to a
non-zero value to tunnel through a given HTTP proxy.
CURLOPT_FILETIME: Set this option to a non-zero
value for CURL to attempt to retrieve the modification date of the
remote document. You can then retrieve this value using the
CURLINFO_FILETIME option with
curl_getinfo.
CURLOPT_MAXREDIRS: Pass a long as a value that
defines the maximum amount of HTTP redirections to follow. Use this
option alongside CURLOPT_FOLLOWLOCATION.
CURLOPT_MAXCONNECTS: Pass a long as a value that
defines the maximum amount of persistent connections that are allowed.
When the limit is reached, CURLOPT_CLOSEPOLICY
is used to figure out which connection to close.
CURLOPT_CLOSEPOLICY: Set this option to either
CURLCLOSEPOLICY_LEAST_RECENTLY_USED or
CURLCLOSEPOLICY_OLDEST.
There are three other CURLCLOSEPOLICY_
constants, but CURL does not support them yet.
CURLOPT_FRESH_CONNECT: Set this option to a
non-zero value to force the use of a new connection instead of a
cached one.
CURLOPT_FORBID_REUSE: Set this option to a
non-zero value to force the connection to explicitly close when its
finished processing, and not be pooled for reuse.
CURLOPT_CONNECTTIMEOUT: Pass a long as a value
that defines the number of seconds to wait whilst trying to connect.
Use zero to wait indefinitely.
CURLOPT_BINARYTRANSFER: Set this option to a
non-zero value to return the raw output when
CURLOPT_RETURNTRANSFER is used.
CURLOPT_PROXYTYPE: Set this option to either
CURLPROXY_HTTP (default) or
CURLPROXY_SOCKS5. This was added in CURL 7.10.
CURLOPT_BUFFERSIZE: Pass a long as a value
that defines the size of the buffer to use for each read. There is no
guarantee this request will be fulfilled, however. This was added
in CURL 7.10.
CURLOPT_HTTPGET: Set this option to a non-zero
value to reset the HTTP request method to GET. Since GET is the
default, this is only necessary if the request method has been
changed.
CURLOPT_HTTP_VERSION: Set this option to
CURL_HTTP_VERSION_NONE (default, lets CURL
decide which version to use),
CURL_HTTP_VERSION_1_0 (forces HTTP/1.0),
or CURL_HTTP_VERSION_1_1 (forces HTTP/1.1).
CURLOPT_CRLF: Set this option to a non-zero
value if you want to convert Unix newlines to CRLF newlines on
transfers.
CURLOPT_PROXYPORT: Pass a long as a value
that defines the port number of the proxy to connect to. This port
number can also be set in CURLOPT_PROXY.
CURLOPT_UNRESTRICTED_AUTH: Set this option to
a non-zero value to keep sending the username and password when
following locations (using
CURLOPT_FOLLOWLOCATION), even when the
hostname has changed.
CURLOPT_FTP_USE_EPRT: Set this option to a
non-zero value to use EPRT (and LPRT) when doing active FTP downloads.
Use zero to disable EPRT and LPRT and use PORT only.
CURLOPT_HTTPAUTH: Pass a long as a value that
defines the HTTP authentication method(s) you wish to use. The options
are: CURLAUTH_BASIC,
CURLAUTH_DIGEST,
CURLAUTH_GSSNEGOTIATE,
CURLAUTH_NTLM,
CURLAUTH_ANY, and
CURLAUTH_ANYSAFE.
You can use the bitwise | (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.
CURLAUTH_ANY is an alias for
CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM
and CURLAUTH_ANYSAFE is an alias for
CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM.
The value parameter should be a string for
the following values of the option
parameter:
CURLOPT_URL: This is the URL that you
want PHP to fetch. You can also set this option when
initializing a session with the curl_init
function.
CURLOPT_USERPWD: Pass a string
formatted in the [username]:[password] manner, for PHP to use
for the connection.
CURLOPT_PROXYUSERPWD: Pass a string
formatted in the [username]:[password] format for connection
to the HTTP proxy.
CURLOPT_RANGE: Pass the specified range
you want. It should be in the "X-Y" format, where X or Y may
be left out. The HTTP transfers also support several
intervals, separated with commas as in X-Y,N-M.
CURLOPT_POSTFIELDS: Pass a string
containing the full data to post in an HTTP "POST" operation.
CURLOPT_REFERER: Pass a string
containing the "referer" header to be used in an HTTP request.
CURLOPT_USERAGENT: Pass a string
containing the "user-agent" header to be used in an HTTP
request.
CURLOPT_FTPPORT: Pass a string
containing 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_COOKIE: Pass a string
containing the content of the cookie to be set in the HTTP
header.
CURLOPT_SSLCERT: Pass a string
containing the filename of PEM formatted certificate.
CURLOPT_SSLCERTPASSWD: Pass a string
containing the password required to use the
CURLOPT_SSLCERT certificate.
CURLOPT_COOKIEFILE: Pass a string
containing 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.
CURLOPT_CUSTOMREQUEST: Pass a string to
be used instead of GET or
HEAD when doing an HTTP request. This is
useful for doing DELETE or other, more
obscure, HTTP requests. Valid values are things like
GET, POST, and so on;
i.e. do not enter a whole HTTP request line here. For instance,
entering 'GET /index.html HTTP/1.0\r\n\r\n' would be incorrect.
Don't do this without making sure your server supports the
command first.
CURLOPT_PROXY: Give the name of the HTTP
proxy to tunnel requests through.
CURLOPT_INTERFACE: Pass the name of the
outgoing network interface to use. This can be an interface name,
an IP address or a host name.
CURLOPT_KRB4LEVEL: Pass the KRB4 (Kerberos
4) security level. Any of the following values (in
order from least to most powerful) are valid: 'clear', 'safe',
'confidential', 'private'. If the string does not match one of
these, then 'private' is used. Setting this Option to
NULL, will disable KRB4 security. Currently KRB4
security only works with FTP transactions.
CURLOPT_HTTPHEADER: Pass an array of HTTP
header fields to set.
CURLOPT_QUOTE: Pass an array of FTP commands
to perform on the server prior to the FTP request.
CURLOPT_POSTQUOTE: Pass an array of FTP
commands to execute on the server, after the FTP request has been
performed.
CURLOPT_RANDOM_FILE: Pass a string that
contains a filename to be used to seed the random number generator
for SSL.
CURLOPT_EGBSOCKET: Like
CURLOPT_RANDOM_FILE except you pass a string
that contains a filename to an Entropy Gathering Daemon socket.
CURLOPT_CAPATH: Pass a string that
contains a directory that holds multiple CA certificates. Use this
option alongside CURLOPT_SSL_VERIFYPEER.
CURLOPT_COOKIEJAR: Pass a string that
contains a filename to save all internal cookies to when the
connection closes.
CURLOPT_SSL_CIPHER_LIST: Pass a string that
contains a list of ciphers to use for SSL. For example,
RC4-SHA and TLSv1 are valid
cipher lists.
CURLOPT_SSLKEY: Pass a string that
contains the filename of your private SSL key.
CURLOPT_SSLKEYTYPE: Pass a string that
contains what key type your private SSL key is. Supported key types
are "PEM" (default), "DER",
and "ENG".
CURLOPT_SSLKEYPASSWD: Pass a string that
contains the secret password to use your private SSL key.
Since this option contains a sensitive password, remember to keep
the PHP script it is contained within safe.
CURLOPT_SSLENGINE: Pass a string that
contains the identifier for the crypto engine of your private key.
CURLOPT_SSLENGINE_DEFAULT: Pass a string that
contains the identifier for the crypto engine used for asymmetric
crypto operations.
CURLOPT_SSLCERTTYPE: Pass a string that
contains what format your certificate is in. Supported formats
are "PEM" (default), "DER",
and "ENG". This was added in CURL 7.9.3.
CURLOPT_ENCODING: Pass a string that
sets the contents of the Accept-Encoding: header,
and enables decoding of the response. Supported encodings are
"identity", "deflate", and
"gzip". If an empty string, "",
is passed, a header containing all supported encoding types is sent.
CURLOPT_HTTP200ALIASES: Pass an array of
strings that will be treated as valid HTTP 200 responses. This was
added in CURL 7.10.3.
The following options expect a file descriptor that is obtained
by using the fopen function:
CURLOPT_FILE: The file where the output
of your transfer should be placed, the default is STDOUT.
CURLOPT_INFILE: The file where the
input of your transfer comes from.
CURLOPT_WRITEHEADER: The file to write
the header part of the output into.
CURLOPT_STDERR: The file to write
errors to instead of stderr.
The following options expect a string that is the name of a callback
function:
CURLOPT_WRITEFUNCTION: Pass 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. Return the number of bytes written.
CURLOPT_READFUNCTION: Pass 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 EOF.
CURLOPT_PASSWDFUNCTION: Pass 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.
CURLOPT_HEADERFUNCTION: Pass 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.
Initializing a new CURL session and fetching a webpage
]]>