![]() |
Home
iRate! IceMelon IM Tutorials Headlines CoolSites PHP Functions |
Most Referenced Functions » google_pagerank() » preg_replace() » imagecreatefrompng() » site_pageranks() » imagepng() » imagedestroy() » imagestring() » imagecolorallocate() » htmlentities() » preg_match() » fopen() » header() » getimagesize() » htmlspecialchars() » ob_start() » strstr() » session_start() » preg_match_all() » ob_flush() » strpos() » flush() » setcookie() » str_replace() » array2vars() » nl2br() » preg_split() » ereg() » ereg_replace() » urlencode() » readgzfile() Become a sponsor for $15/month. Link is sitewide - PR5 homepage, 20+ PR4 pages, 90+ PR3 pages. Email dave[AT]icemelon[D0T]c0m. |
PHP Functions
Function: curl_setopt (PHP 4 >= 4.0.2, PHP 5) curl_setopt -- Set an option for a CURL transferDescriptionbool curl_setopt ( resource ch, int option, mixed value )Set an option for a CURL session identified by the ch parameter. option specifies which option to set, and value specifies the value for the option given. value should be a bool for the following values of the option parameter: Option Set value to Notes CURLOPT_BINARYTRANSFER TRUE to return the raw output when CURLOPT_RETURNTRANSFER is used. CURLOPT_CRLF TRUE to convert Unix newlines to CRLF newlines on transfers. CURLOPT_DNS_USE_GLOBAL_CACHE TRUE to use a global DNS cache. This option is not thread-safe and is enabled by default. CURLOPT_FAILONERROR TRUE 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_FILETIME TRUE 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_FOLLOWLOCATION TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is set). CURLOPT_FORBID_REUSE TRUE to force the connection to explicitly close when it has finished processing, and not be pooled for reuse. CURLOPT_FRESH_CONNECT TRUE to force the use of a new connection instead of a cached one. CURLOPT_FTP_USE_EPRT TRUE to use EPRT (and LPRT) when doing active FTP downloads. Use FALSE to disable EPRT and LPRT and use PORT only. Added in PHP 5.0.0. CURLOPT_FTP_USE_EPSV TRUE to first try an EPSV command for FTP transfers before reverting back to PASV. Set to FALSE to disable EPSV. CURLOPT_FTPAPPEND TRUE to append to the remote file instead of overwriting it. CURLOPT_FTPASCII An alias of CURLOPT_TRANSFERTEXT . Use that instead. CURLOPT_FTPLISTONLY TRUE to only list the names of an FTP directory. CURLOPT_HEADER TRUE to include the header in the output. CURLOPT_HTTPGET TRUE 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_HTTPPROXYTUNNEL TRUE to tunnel through a given HTTP proxy. CURLOPT_MUTE TRUE to be completely silent with regards to the CURL functions. CURLOPT_NETRC TRUE to scan your ~/.netrc file to find your username and password for the remote site that you're establishing a connection with. CURLOPT_NOBODY TRUE to exclude the body from the output. CURLOPT_NOPROGRESS TRUE to disable the progress meter for CURL transfers. Note: PHP automatically sets this option to TRUE , this should only be changed for debugging purposes.
value should be an integer for the following values of the option parameter: Option Set value to Notes CURLOPT_BUFFERSIZE The size of the buffer to use for each read. There is no guarantee this request will be fulfilled, however. Added in CURL 7.10 and PHP 5.0.0. CURLOPT_CLOSEPOLICY Either CURLCLOSEPOLICY_LEAST_RECENTLY_USED or CURLCLOSEPOLICY_OLDEST . There are three other CURLCLOSEPOLICY_ constants, but CURL does not support them yet. CURLOPT_CONNECTTIMEOUT The number of seconds to wait whilst trying to connect. Use 0 to wait indefinitely. CURLOPT_DNS_CACHE_TIMEOUT The number of seconds to keep DNS entries in memory. This option is set to 120 (2 minutes) by default. CURLOPT_FTPSSLAUTH The FTP authentication method (when is activated): CURLFTPAUTH_SSL (try SSL first), CURLFTPAUTH_TLS (try TLS first), or CURLFTPAUTH_DEFAULT (let CURL decide). Added in CURL 7.12.2 and PHP 5.1.0. CURLOPT_HTTP_VERSION 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_HTTPAUTH The HTTP authentication method(s) 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 . CURLAUTH_ANYSAFE is an alias for CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM . Added in PHP 5.0.0. CURLOPT_INFILESIZE The expected size, in bytes, of the file when uploading a file to a remote site. CURLOPT_LOW_SPEED_LIMIT The transfer speed, in bytes per second, that the transfer should be below during CURLOPT_LOW_SPEED_TIME seconds for PHP to consider the transfer too slow and abort. CURLOPT_LOW_SPEED_TIME The number of seconds the transfer should be below CURLOPT_LOW_SPEED_LIMIT for PHP to consider the transfer too slow and abort. CURLOPT_MAXCONNECTS The maximum amount of persistent connections that are allowed. When the limit is reached, CURLOPT_CLOSEPOLICY is used to determine which connection to close. CURLOPT_MAXREDIRS The maximum amount of HTTP redirections to follow. Use this option alongside CURLOPT_FOLLOWLOCATION . CURLOPT_PORT An alternative port number to connect to. CURLOPT_PROXYAUTH The HTTP authentication method(s) to use for the proxy connection. Use the same bitmasks as described in CURLOPT_HTTPAUTH . For proxy authentication, only CURLAUTH_BASIC and CURLAUTH_NTLM are currently supported. Added in CURL 7.10.7 and PHP 5.1.0. CURLOPT_PROXYPORT The port number of the proxy to connect to. This port number can also be set in CURLOPT_PROXY . Added in PHP 5.0.0. CURLOPT_PROXYTYPE Either CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5 . Added in CURL 7.10 and PHP 5.0.0. CURLOPT_RESUME_FROM The offset, in bytes, to resume a transfer from. CURLOPT_SSL_VERIFYHOST 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. CURLOPT_SSLVERSION 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. CURLOPT_TIMECONDITION How CURLOPT_TIMEVALUE is treated. Use CURL_TIMECOND_IFMODSINCE to return the page only if it has been modified since the time specified in CURLOPT_TIMEVALUE . If it hasn't been modified, a "304 Not Modified" header will be returned assuming CURLOPT_HEADER is TRUE . Use CURL_TIMECOND_ISUNMODSINCE for the reverse effect. CURL_TIMECOND_IFMODSINCE is the default. Added in PHP 5.1.0. CURLOPT_TIMEOUT The maximum number of seconds to allow CURL functions to execute. CURLOPT_TIMEVALUE The time in seconds since January 1st, 1970. The time will be used by CURLOPT_TIMECONDITION . By default, CURL_TIMECOND_IFMODSINCE is used.
value should be a string for the following values of the option parameter: Option Set value to Notes CURLOPT_CAINFO The name of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with CURLOPT_SSL_VERIFYPEER . CURLOPT_CAPATH A directory that holds multiple CA certificates. Use this option alongside CURLOPT_SSL_VERIFYPEER . CURLOPT_COOKIE The contents of the "Set-Cookie: " header to be used in the HTTP request. CURLOPT_COOKIEFILE 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_COOKIEJAR The name of a file to save all internal cookies to when the connection closes. CURLOPT_CUSTOMREQUEST A custom request method to use instead of "GET" or "HEAD" when doing a HTTP request. This is useful for doing "DELETE" or other, more obscure HTTP requests. Valid values are things like "GET" , "POST" , "CONNECT" 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. Note: Don't do this without making sure your server supports the custom request method first. Note: Since this option contains a sensitive password, remember to keep the PHP script it is contained within safe.
value should be an array for the following values of the option parameter: Option Set value to Notes CURLOPT_HTTP200ALIASES An array of HTTP 200 responses that will be treated as valid responses and not as errors. Added in CURL 7.10.3 and PHP 5.0.0. CURLOPT_HTTPHEADER An array of HTTP header fields to set. CURLOPT_POSTQUOTE An array of FTP commands to execute on the server after the FTP request has been performed. CURLOPT_QUOTE An array of FTP commands to execute on the server prior to the FTP request.
value should be a stream resource (using fopen() , for example) for the following values of the option parameter: Option Set value to Notes CURLOPT_FILE The file that the transfer should be written to. The default is STDOUT (the browser window). CURLOPT_INFILE The file that the transfer should be read from when uploading. CURLOPT_STDERR An alternative location to output errors to instead of STDERR . CURLOPT_WRITEHEADER The file that the header part of the transfer is written to.
value should be a string that is the name of a valid callback function for the following values of the option parameter: Option Set value to Notes CURLOPT_HEADERFUNCTION 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. CURLOPT_PASSWDFUNCTION 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_READFUNCTION 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_WRITEFUNCTION 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.
Example 1. Initializing a new CURL session and fetching a webpage <?php // create a new CURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.example.com/"); curl_setopt($ch, CURLOPT_HEADER, false); // grab URL and pass it to the browser curl_exec($ch); // close CURL resource, and free up system resources curl_close($ch); ?> Related Function(s) |