The phpcurl function is a file transfer tool that uses the URL syntax. it supports FTP, FTPS, httphtppsscpsftptelnetdictfile, and LDAP. Curl supports SSL certificate, HTTPPOST, HTTPPUT, FTP upload, kerberos, HTT-based Upload, proxy, cookie, user + password php curl function application method-simulate a browser
Curl is a FILE transfer tool using URL syntax. it supports FTP, FTPS, http htpps scp sftp tftp telnet dict file and LDAP. Curl supports SSL certificates, http post, http put, and FTP uploads, kerberos, HTT-based Upload, proxy, cookie, user + password proof, file transfer recovery, http proxy channel and a large number of other useful techniques.
For more information, see the reference manual.
Php does not extend this function by default, but it still does not take effect. Open the PHP installation directory, search for the following three files: ssleay32.dll, libeay32.dll, and php_curl.dll, copy them to the system32 folder in the system directory one by one, and modify php. ini file, find; extension = php_curl.dll line, remove the previous; number, save, restart the server. Create a php file in the site directory with the following content:
?
$ch = curl_init("http://www.php.net"); curl_exec($ch); curl_close($ch);
? Preview if you can open the http://www.php.net, it means the installation is successful.
For linux and unix installation, you may need to download the curldatabase from http://curl.haxx.se/or another website.
____________________________________________________________
The following parameters are used for this function:
Bool curl_setopt (int ch, string option, mixed value)
The curl_setopt () function sets options for a CURL session. The option parameter is the setting you want, and the value is the value given by this option.
The values of the following options will be used as long integer (specified in the option parameter ):
CURLOPT_INFILESIZE: When you upload a file to a remote site, this option tells PHP about the size of the file to be uploaded.
CURLOPT_VERBOSE: If you want CURL to report every unexpected event, set this option to a non-zero value.
CURLOPT_HEADER: If you want to include a header in the output, set this option to a non-zero value.
CURLOPT_NOPROGRESS: If you do not display a process entry for CURL transmission in PHP, set this option to a non-zero value. Note: PHP automatically sets this option to a non-zero value. you should change this option only for debugging purposes.
CURLOPT_NOBODY: If you do not want to include the body in the output, set this option to a non-zero value.
CURLOPT_FAILONERROR: If you want PHP not to be displayed when an error occurs (HTTP code returns a value greater than or equal to 300), set this option to a non-zero value. By default, a normal page is returned, ignoring the code.
CURLOPT_UPLOAD: If you want PHP to prepare for upload, set this option to a non-zero value.
CURLOPT_POST: If you want PHP to create a regular http post, set this option to a non-zero value. This POST is a common application/x-www-from-urlencoded type, most of which are used by HTML forms.
CURLOPT_FTPLISTONLY: set this option to a non-zero value. PHP will list the FTP directory names.
CURLOPT_FTPAPPEND: set this option to a non-zero value. PHP overwrites the remote application file.
CURLOPT_NETRC: set this option to a non-zero value. PHP will be in your ~. In the/netrc file, find the username and password of the remote site you want to establish a connection.
CURLOPT_FOLLOWLOCATION: set this option to a non-zero value (like "Location:") header. the server will send it as part of the HTTP header (note that this is recursive, PHP will send the header like "Location ).
CURLOPT_PUT: set this option to a non-zero value to upload a file over HTTP. To upload this file, you must set the CURLOPT_INFILE and CURLOPT_INFILESIZE options.
CURLOPT_MUTE: set this option to a non-zero value, and PHP will completely silence the CURL function.
CURLOPT_TIMEOUT: specifies the maximum number of seconds for a long integer.
CURLOPT_LOW_SPEED_LIMIT: sets the number of long integers to control the number of bytes transmitted.
CURLOPT_LOW_SPEED_TIME: sets the number of long integers and controls the number of seconds to transmit the number of bytes specified by CURLOPT_LOW_SPEED_LIMIT.
CURLOPT_RESUME_FROM: transmits a long integer parameter containing the byte offset address (the start form you want to transfer ).
CURLOPT_SSLVERSION: transmits a long parameter containing the SSL version. By default, PHP will be determined by its own efforts. you must set it manually in more security scenarios.
CURLOPT_TIMECONDITION: transmits a long parameter to specify how to process the CURLOPT_TIMEVALUE parameter. You can set this parameter to TIMECOND_IFMODSINCE or TIMECOND_ISUNMODSINCE. This is only used for HTTP.
CURLOPT_TIMEVALUE: the number of seconds from January 1, to the present. This time will be used by the CURLOPT_TIMEVALUE option as the specified value, or by the default TIMECOND_IFMODSINCE.
The values of the following options will be used as strings:
CURLOPT_URL: the URL you want to retrieve with PHP. You can also set this option when initializing with the curl_init () function.
CURLOPT_USERPWD: transmits a string in the [username]: [password] style, which serves PHP to connect.
CURLOPT_PROXYUSERPWD: transmits a string in the format of [username]: [password] to connect to the HTTP proxy.
CURLOPT_RANGE: transmits a range you want to specify. It should be in the "X-Y" format, X or Y is excluded. HTTP shipping also supports several intervals separated by sentences (X-Y, N-M ).
CURLOPT_POSTFIELDS: a string that transmits all data for the HTTP "POST" operation.
CURLOPT_REFERER: a string containing the "referer" header in an HTTP request.
CURLOPT_USERAGENT: a string containing the "user-agent" header in an HTTP request.
CURLOPT_FTPPORT: transmits an IP address that contains the IP address used by the ftp "POST" command. This POST command tells the remote server to connect to the specified IP address. This string can be an IP address, a host name, a network interface name (under UNIX), or '-' (using the default IP address of the system ).
CURLOPT_COOKIE: transmits a header connection containing the HTTP cookie.
CURLOPT_SSLCERT: transmits a string containing the PEM format certificate.
CURLOPT_SSLCERTPASSWD: Pass a password that contains the password required to use the CURLOPT_SSLCERT certificate.
CURLOPT_COOKIEFILE: a string that transmits the name of a file containing cookie data. This cookie file can be in the Netscape format or heap containing the HTTP header in the file.
CURLOPT_CUSTOMREQUEST: When an HTTP request is sent, a character is used by GET or HEAD. It is helpful to perform DELETE or other operations. 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 commands. The following options require a file description (obtained by using the fopen () function ):
CURLOPT_FILE: This file will be the output file you placed for transfer. the default value is STDOUT.
CURLOPT_INFILE: This file is the input file you sent.
CURLOPT_WRITEHEADER: This file contains the header of your output.
CURLOPT_STDERR: This file is written incorrectly, not stderr. This example is used to obtain the page to be logged on. The current practice is to log on every time or every time, and the users who need it have made improvements.
Here are some examples of website deductions:
Example 1:
?
$ Cookie_jar = tempnam ('. /tmp ', 'cookies'); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, 'http ://******'); curl_setopt ($ ch, CURLOPT_POST, 1); $ request = 'Email _ address = & password = & action = '; curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ request ); // Save the returned cookie information in the $ cookie_jar file curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookie_jar); // Set whether the returned data automatically displays curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // Set whether to display the header information curl_setopt ($ ch, CURLOPT_HEADER, false); // Set whether to output the page content curl_setopt ($ ch, CURLOPT_NOBODY, false ); curl_exec ($ ch); curl_close ($ ch); // get data after login Example 2: $ ch2 = curl_init (); curl_setopt ($ ch2, CURLOPT_URL, 'http: // ***** '); curl_setopt ($ ch2, CURLOPT_HEADER, false); curl_setopt ($ ch2, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch2, CURLOPT_COOKIEFILE, $ cookie_jar); $ orders = curl_exec ($ ch2); echo ''; echo strip_tags ($ orders); echo''; curl_close ($ ch2 ); practice has proved stable: Example 3: set_time_limit (0); function _ rand () {$ length = 26; $ chars = "0123456789 abcdefghijklmnopqrstuvwxyz"; $ max = strlen ($ chars) -1; mt_srand (double) microtime () * 1000000); $ string = ''; for ($ I = 0; $ I' http://www.baidu.com/ ', CURLOPT_HEADER => false); curl_setopt_array ($ ch, $ options); curl_exec ($ ch); curl_close ($ ch); fclose ($ fp );
?
Configurable parameters include:
CURLOPT_AUTOREFERER
Automatically set referer information in the header
CURLOPT_BINARYTRANSFER
When CURLOPT_RETURNTRANSFER is enabled, data is returned.
CURLOPT_COOKIESESSION
When curl is enabled, only one session cookie is passed and other cookies are ignored. by default, curl returns all cookies to the server. Session cookie is a cookie used to determine whether a session on the server is valid.
CURLOPT_CRLF
When it is enabled, the Unix line break is converted into a carriage return line break.
CURLOPT_DNS_USE_GLOBAL_CACHE
When enabled, a global DNS cache is enabled. this option is thread-safe and the default value is true.
CURLOPT_FAILONERROR
The HTTP status code is displayed. the default behavior is to ignore the HTTP information whose number is less than or equal to 400.
CURLOPT_FILETIME
When enabled, the system tries to modify the information in the remote document. The result is returned through the CURLINFO_FILETIME option of the curl_getinfo () function.
CURLOPT_FOLLOWLOCATION
When enabled, the "Location:" returned by the server is placed in the header and recursively returned to the server. you can use CURLOPT_MAXREDIRS to limit the number of recursive responses.
CURLOPT_FORBID_REUSE
After the interaction is completed, the connection is forcibly disconnected and cannot be reused.
CURLOPT_FRESH_CONNECT
Force a new connection to replace the connection in the cache.
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
When enabled, the header file information is output as a data stream.
CURLOPT_HTTPGET
When enabled, the HTTP method is set to GET. because GET is set by default, it is used only when it is modified.
CURLOPT_HTTPPROXYTUNNEL
It is transmitted through the HTTP proxy when it is enabled.
CURLOPT_MUTE
This section describes how to restore the default values of all modified parameters in the curl function.
CURLOPT_NETRC
After the connection is established, access ~ /. The netrc file obtains the user name and password to connect to the remote site.
CURLOPT_NOBODY
When enabled, the HTML body section is not output.
CURLOPT_NOPROGRESS
Disable the curl transfer progress bar when enabling. the default value of this item is true.
CURLOPT_NOSIGNAL
When enabled, ignore all curl signals sent to php. This option is enabled by default during SAPI multi-thread transmission.
CURLOPT_POST
When it is enabled, a conventional POST request is sent. the type is application/x-www-form-urlencoded, just like form submission.
CURLOPT_PUT
When enabled, files can be sent over HTTP. both CURLOPT_INFILE and CURLOPT_INFILESIZE must be set.
CURLOPT_RETURNTRANSFER
The information obtained by curl_exec () is returned in the form of a file stream, rather than directly output.
CURLOPT_SSL_VERIFYPEER
FALSE to stop cURL from verifying the peer's certificate. alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 ). TRUE by default as of cURL 7.10. default bundle installed as of cURL 7.10.
CURLOPT_TRANSFERTEXT
TRUE 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 STDOUT to binary mode.
CURLOPT_UNRESTRICTED_AUTH
The username and password information is continuously appended to multiple locations in the header generated by CURLOPT_FOLLOWLOCATION, even if the domain name has changed.
CURLOPT_UPLOAD
Enable file transfer
CURLOPT_VERBOSE
When enabled, all information is reported and stored in STDERR or the specified CURLOPT_STDERR.
CURLOPT_BUFFERSIZE
The size of the data read into the cache each time. This value is filled every time.
CURLOPT_CLOSEPOLICY
Either CURLCLOSEPOLICY_LEAST_RECENTLY_USED or CURLCLOSEPOLICY_OLDEST exists, but curl is not supported yet ..
CURLOPT_CONNECTTIMEOUT
The waiting time before the connection is initiated. if it is set to 0, no waiting is performed.
CURLOPT_DNS_CACHE_TIMEOUT
Set the time for saving DNS information in the memory. the default value is 120 seconds.
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 ).
CURLOPT_HTTP_VERSION
Set the HTTP protocol used by curl, CURL_HTTP_VERSION_NONE (let curl determine by itself), CURL_HTTP_VERSION_1_0 (HTTP/1.0), CURL_HTTP_VERSION_1_1 (HTTP/1.1)
CURLOPT_HTTPAUTH
The HTTP verification method used. optional values include CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, CURLAUTH_NTLM, CURLAUTH_ANY, and CURLAUTH_ANYSAFE. multiple values can be separated by the "|" operator, curl allows the server to select the best value. CURLAUTH_ANY is equivalent to CURLAUTH_BASIC | CURLAUTH_DIGEST | digest | CURLAUTH_NTLM, CURLAUTH_ANYSAFE is equivalent to CURLAUTH_DIGEST | digest | CURLAUTH_NTLM
CURLOPT_INFILESIZE
Set the size of the uploaded file
CURLOPT_LOW_SPEED_LIMIT
When the transmission speed is less than CURLOPT_LOW_SPEED_LIMIT, PHP will determine whether to cancel the transmission because it is too slow based on CURLOPT_LOW_SPEED_TIME.
CURLOPT_LOW_SPEED_TIME
The number of seconds the transfer shocould be below CURLOPT_LOW_SPEED_LIMIT for PHP to consider the transfer too slow and abort.
When the transmission speed is less than CURLOPT_LOW_SPEED_LIMIT, PHP will determine whether to cancel the transmission because it is too slow based on CURLOPT_LOW_SPEED_TIME.
CURLOPT_MAXCONNECTS
The maximum number of connections allowed. if the maximum number is exceeded, the CURLOPT_CLOSEPOLICY is used to determine which connections should be stopped.
CURLOPT_MAXREDIRS
Specifies the maximum number of HTTP redirects. this option is used with CURLOPT_FOLLOWLOCATION.
CURLOPT_PORT
An optional parameter used to specify the number of connection ports
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.
CURLOPT_PROXYPORT
The port number of the proxy to connect to. This port number can also be set in CURLOPT_PROXY.
CURLOPT_PROXYTYPE
Either CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5.
CURLOPT_RESUME_FROM
Transmit a byte offset when resuming transmission (used for resumable transmission)
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 this must be set manually.
CURLOPT_TIMECONDITION
If it has been edited after a certain time specified by CURLOPT_TIMEVALUE, CURL_TIMECOND_IFMODSINCE is used to return to the page. if it has Not been Modified and CURLOPT_HEADER is true, a header of "304 Not Modified" is returned, if CURLOPT_HEADER is false, use CURL_TIMECOND_ISUNMODSINCE. the default value is CURL_TIMECOND_IFMODSINCE.
CURLOPT_TIMEOUT
Sets the maximum number of seconds that curl can be executed.
CURLOPT_TIMEVALUE
Set a timestamp used by CURLOPT_TIMECONDITION. by default, CURL_TIMECOND_IFMODSINCE is used.
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
Set the content in the "Set-Cookie:" section of the HTTP request.
CURLOPT_COOKIEFILE
The name of the file containing the cookie information. the cookie file can be in Netscape format or HTTP header information.
CURLOPT_COOKIEJAR
Name of the file that stores cookie information after the connection is closed
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" wocould be incorrect.
Note: Don't do this without making sure the server supports the custom request method first.
CURLOPT_EGBSOCKET
Like CURLOPT_RANDOM_FILE, except t a filename to an Entropy Gathering Daemon socket.
CURLOPT_ENCODING
The content in "Accept-Encoding:" in the header. the supported Encoding formats are: "identity", "deflate", and "gzip ". If it is set to an empty string, all encoding formats are supported.
CURLOPT_FTPPORT
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_INTERFACE
The name used in the external network interface can be an interface name, IP address or host name.
CURLOPT_KRB4LEVEL
KRB4 (Kerberos 4) security level settings can be one of the following values: "clear", "safe", "confidential", "private ". The default value is "private". if it is set to null, KRB4 is disabled. Currently, KRB4 can only be used for FTP transmission.
CURLOPT_POSTFIELDS
The "POST" operation in HTTP. If you want to transfer a file, [email protected]
CURLOPT_PROXY
Set the HTTP proxy server
CURLOPT_PROXYUSERPWD
The username and password used to connect to the proxy server in the format of [username]: [password.
CURLOPT_RANDOM_FILE
Set the name of the file that stores the random seed used by SSL.
CURLOPT_RANGE
Sets an HTTP Transport range, which can be set as a X-Y, and if there are multiple HTTP transport, separate multiple values, such as: "X-Y, n-M ".
CURLOPT_REFERER
Set the value of "Referer:" in the header.
CURLOPT_SSL_CIPHER_LIST
A list of ciphers to use for SSL. For example, RC4-SHA and TLSv1 are valid cipher lists.
CURLOPT_SSLCERT
Pass a string that contains a PEM certificate.
CURLOPT_SSLCERTPASSWD
Pass a password that contains the password required to use the CURLOPT_SSLCERT certificate.
CURLOPT_SSLCERTTYPE
The format of the certificate. Supported formats are "PEM" (default), "DER", and "ENG ".
CURLOPT_SSLENGINE
The identifier for the crypto engine of the private SSL key specified in CURLOPT_SSLKEY.
CURLOPT_SSLENGINE_DEFAULT
The identifier for the crypto engine used for asypolicric crypto operations.
CURLOPT_SSLKEY
The name of a file containing a private SSL key.
CURLOPT_SSLKEYPASSWD
The secret password needed to use the private SSL key specified in CURLOPT_SSLKEY.
Note: Since this option contains a sensitive password, remember to keep the PHP script it is contained within safe.
CURLOPT_SSLKEYTYPE
The key type of the private SSL key specified in CURLOPT_SSLKEY. Supported key types are "PEM" (default), "DER", and "ENG ".
CURLOPT_URL
You can also set the URL address in the curl_init () function of PHP.
CURLOPT_USERAGENT
The HTTP request contains a string containing the "user-agent" header.
CURLOPT_USERPWD
Pass the username and password required for a connection in the format of [username]: [password].
CURLOPT_HTTP200ALIASES
The setting no longer processes the HTTP 200 response in the form of an error. the format is an array.
CURLOPT_HTTPHEADER
Sets an array of transmitted content in a header.
CURLOPT_POSTQUOTE
An array of FTP commands to execute on the server after the FTP request has been completed Med.
CURLOPT_QUOTE
An array of FTP commands to execute on the server prior to the FTP request.
CURLOPT_FILE
Set the location of the output file. The value is a resource type. the default value is STDOUT (browser ).
CURLOPT_INFILE
The address of the file to be read when uploading the file. The value is a resource type.
CURLOPT_STDERR
Set an error output address. The value is a resource type that replaces the default STDERR.
CURLOPT_WRITEHEADER
Sets the address of the file to which the header is written. The value is a resource type.
CURLOPT_HEADERFUNCTION
Set a callback function. this function has two parameters: the first is the resource handle of curl, and the second is the output header data. The output of header data must depend on this function to return the size of written data.
CURLOPT_PASSWDFUNCTION
Set a callback function with three parameters: the first is the resource handle of curl, the second is a password prompt, and the third parameter is the maximum allowed password length. Returns the password value.
CURLOPT_READFUNCTION
Set a callback function with two parameters: the first is the resource handle of curl and the second is the data read. Data reading must depend on this function. The size of the data to be read, such as 0 or EOF.
CURLOPT_WRITEFUNCTION
Set a callback function with two parameters: the first is the resource handle of curl and the second is the written data. Data writing must depend on this function. Returns the exact size of the written data.
The curl_copy_handle () function is used to copy all content and parameters of a curl connection resource.
$ Ch = curl_init ("http://www.baidu.com /");
$ Another = curl_copy_handle ($ ch );
Curl_exec ($ another );
Curl_close ($ another );
The curl_error () function returns a string containing the current session error message.
The curl_errno () function returns a number that contains the current session error message.
The curl_multi_init () function initializes a curl batch processing handle resource.
The curl_multi_add_handle () function adds a separate curl handle resource to the curl batch processing session. The curl_multi_add_handle () function has two parameters. The first parameter indicates a curl batch processing handle resource, and the second parameter indicates a separate curl handle resource.
The curl_multi_exec () function is used to parse a curl batch processing handle. the curl_multi_exec () function has two parameters. The first parameter indicates a batch processing handle resource, the second parameter is a reference value parameter, indicating the number of individual curl handle resources to be processed.
The curl_multi_remove_handle () function removes a handle resource from the curl batch processing handle. the curl_multi_remove_handle () function has two parameters. The first parameter indicates a curl batch processing handle resource, the second parameter represents a separate curl handle resource.
The curl_multi_close () function is used to close a batch processing handle resource.
?
$ch1 = curl_init();$ch2 = curl_init();curl_setopt($ch1, CURLOPT_URL, "http://www.baidu.com/");curl_setopt($ch1, CURLOPT_HEADER, 0);curl_setopt($ch2, CURLOPT_URL, "http://www.google.com/");curl_setopt($ch2, CURLOPT_HEADER, 0);$mh = curl_multi_init();curl_multi_add_handle($mh,$ch1);curl_multi_add_handle($mh,$ch2);do {curl_multi_exec($mh,$flag);} while ($flag > 0);curl_multi_remove_handle($