PHP Curl Function Application Method of simulation browser
Curl is a routing file tool that uses URL syntax to support FTP, FTPS, HTTP htpps SCP SFTP TFTP, TELNET DICT file, and LDAP. Curl supports SSL certificates, HTTP POST, http PUT, FTP uploads, Kerberos, HTT-based uploads, proxies, cookies, user + password proofs, file transfer recovery, HTTP proxy channels, and a number of other useful tricks.
See the reference manual
It turns out that PHP does not extend this functionality by default, but it does, but it does not make it effective. Open the PHP installation directory, search the following three files Ssleay32.dll, Libeay32.dll and Php_curl.dll, one by one copy to the system directory under the System32 folder, modify the 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 as follows:
?
? Preview If you can open http://www.php.net, the installation is successful.
Linux and Unix installations can be cumbersome, and you'll need to download the Curl Library from http://curl.haxx.se/or other websites
____________________________________________________________
The following is an argument about this function's use:
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 that you want, and value is the one given by this choice.
The values of the following options are used as long shapes (specified in the option parameter):
Curlopt_infilesize: When you upload a file to a remote site, this option tells PHP the size of your upload file.
Curlopt_verbose: If you want curl to report every unexpected thing, set this option to a value other than 0.
Curlopt_header: If you want to include a header in the output, set this option to a value other than 0.
Curlopt_noprogress: If you do not have PHP display a process bar for the Curl transfer, set this option to a value other than 0. Note: PHP automatically sets this option to a value other than 0, you should only change this option for debugging purposes.
Curlopt_nobody: If you do not want to include the body part in the output, set this option to a value other than 0.
Curlopt_failonerror: If you want PHP to not display when an error occurs (HTTP code returns greater than or equal to 300), set this option to one person other than 0 value. The default behavior is to return a normal page, ignoring the code.
Curlopt_upload: If you want PHP to prepare for uploading, set this option to a value other than 0.
Curlopt_post: If you want PHP to do a regular HTTP POST, set this option to a value other than 0. This post is an ordinary application/x-www-from-urlencoded type, most of which is used by HTML forms.
Curlopt_ftplistonly: Set this option to a value other than 0, PHP lists the list of directory names for FTP.
Curlopt_ftpappend: Set this option to a value other than 0, PHP will apply the remote file instead of overwriting it.
CURLOPT_NETRC: Set this option to a value other than 0, PHP will look in your ~./netrc file for the user name and password of the remote site you want to connect to.
Curlopt_followlocation: Set this option to a non-0 value (like "Location:") header, the server will send it as part of the HTTP header (note that this is recursive, PHP will be sent as "location:" the head).
Curlopt_put: Set this option to use HTTP to upload a file for a value other than 0. To upload this file you must set the Curlopt_infile and Curlopt_infilesize options.
Curlopt_mute: Set this option to a value other than 0, PHP will be completely silent for the curl function.
Curlopt_timeout: Sets a long shape number, as the maximum continuation of how many seconds.
Curlopt_low_speed_limit: Sets a long shaping number to control how many bytes are transferred.
Curlopt_low_speed_time: Sets a long shape number that controls how many seconds to transmit curlopt_low_speed_limit the specified number of bytes.
Curlopt_resume_from: Pass a long shaping parameter that contains the byte offset address (the start form you want to transfer to).
Curlopt_sslversion: Pass a long parameter that contains the SSL version. The default PHP will be determined by its own efforts, and in more security you must set it up manually.
Curlopt_timecondition: Passes a long parameter that specifies how the Curlopt_timevalue parameter is handled. You can set this parameter to Timecond_ifmodsince or timecond_isunmodsince. This is used only for HTTP.
Curlopt_timevalue: Passes a number of seconds from 1970-1-1 onwards to the present. This time will be used by the Curlopt_timevalue option as the specified value, or by default timecond_ifmodsince.
The values of the following options will be used as strings:
Curlopt_url: This is the URL address you want to retrieve with PHP. You can also set this option when initializing with the Curl_init () function.
Curlopt_userpwd: Pass a shape like [Username]:[password] style string, function PHP to connect.
Curlopt_proxyuserpwd: Pass a string that is formatted as [Username]:[password] to connect to the HTTP proxy.
Curlopt_range: Pass a range that you want to specify. It should be in the "X-y" format, except for X. or Y. HTTP delivery also supports several intervals, separated by a phrase (x-y,n-m).
Curlopt_postfields: A string that passes all data as an HTTP "POST" operation.
Curlopt_referer: A string that contains a "REFERER" header in an HTTP request.
Curlopt_useragent: A string that contains a "user-agent" header in an HTTP request.
Curlopt_ftpport: Pass an IP address that contains the FTP "POST" instruction used. This post command tells the remote server to connect to the IP address we specified. This string can be an IP address, a host name, a network interface name (under Unix), or '-' (using the system default IP address).
Curlopt_cookie: Passes a header connection that contains an HTTP COOKIE.
Curlopt_sslcert: Pass a string containing a certificate in PEM format.
CURLOPT_SSLCERTPASSWD: Pass a password that contains required to use the Curlopt_sslcert certificate.
Curlopt_cookiefile: A string that passes the name of a file that contains cookie data. This cookie file can be a Netscape format, or an HTTP-style header that is stockpiled in a file.
Curlopt_customrequest: When an HTTP request is made, passing a character is used by get or head. For a delete or other operation is beneficial, more pass a string to is used instead of GET or HEAD when doing an HTTP request. This was useful for doing or another, and more obscure, HTTP request. Note: Do not do this before confirming your server support commands. The following options require a file description (obtained by using the fopen () function):
Curlopt_file: This file will be the output file you put in the transfer, the default is stdout.
Curlopt_infile: This file is the input file you sent over.
Curlopt_writeheader: This file is written with the head part of your output.
Curlopt_stderr: This file is written with errors rather than STDERR. To get an example of a page that needs to be signed in, the current practice is to log in once every time, and the person who needs to do it is improved.
Pick a few examples from other websites:
Example one:
?
$cookie _jar = Tempnam ('./tmp ', ' Cookie '); $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); Keep the returned cookie information in the $cookie_jar file curl_setopt ($ch, Curlopt_cookiejar, $cookie _jar); Sets whether the returned data is automatically displayed curl_setopt ($ch, Curlopt_returntransfer, 1); Sets whether to display header information curl_setopt ($ch, Curlopt_header, false); Sets whether to output page content curl_setopt ($ch, Curlopt_nobody, false); Curl_exec ($ch); Curl_close ($ch); Get data After login example two: $ch 2 = Curl_init (); curl_setopt ($ch 2, Curlopt_url, ' http://***** '); curl_setopt ($ch 2, Curlopt_header, false); curl_setopt ($ch 2, Curlopt_returntransfer, 1); curl_setopt ($ch 2, Curlopt_cookiefile, $cookie _jar); ers = Curl_exec ($ch 2); Echo '; echo Strip_tags (ers); Echo '; Curl_close ($ch 2); The practice proved very stable:) Example three: Set_time_limit (0); function _rand () {$length =26; $chars = "0123456789abcdefghijklmnopqrstuvwxyz"; $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);
?
The parameters that can be set are:
Curlopt_autoreferer
Automatically set the Referer information in the header
Curlopt_binarytransfer
Gets the data back when Curlopt_returntransfer is enabled
Curlopt_cookiesession
When enabled, Curl simply passes a session cookie, ignoring other cookies, and by default, curl returns all cookies to the server. Session cookies are cookies that are used to determine if the session on the server is valid.
Curlopt_crlf
Converts a Unix newline character to a carriage return line break when enabled.
Curlopt_dns_use_global_cache
When enabled, a global DNS cache is enabled, which is thread-safe and is true by default.
Curlopt_failonerror
Displays the HTTP status code, with the default behavior of ignoring HTTP messages with numbers less than or equal to 400
Curlopt_filetime
When enabled, attempts to modify the information in the remote document. The resulting information is returned through the curlinfo_filetime option of the Curl_getinfo () function.
Curlopt_followlocation
When enabled, the "location:" returned by the server server is returned to the server recursively in the header, using Curlopt_maxredirs to limit the number of recursive returns.
Curlopt_forbid_reuse
Forced disconnection after completion of the interaction, cannot be reused.
Curlopt_fresh_connect
Forces a new connection to be taken in place of 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 a 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 the list the names of an FTP directory.
Curlopt_header
When enabled, the information for the header file is output as a data stream.
Curlopt_httpget
When enabled, the method for HTTP is set to get, because get is the default, so it is used only if it is modified.
Curlopt_httpproxytunnel
When enabled, it is transmitted over an HTTP proxy.
Curlopt_mute
Restores the default values for all modified parameters in the Curl function.
Curlopt_netrc
After the connection is established, access the ~/.NETRC file to get the user name and password information to connect to the remote site.
Curlopt_nobody
When enabled, the body portion of the HTML is not output.
Curlopt_noprogress
Turns off the progress bar of the curl transfer when enabled, and the default setting for this item is true
Curlopt_nosignal
When enabled, ignores all the signals that curl passes to PHP. This entry is turned on by default when SAPI multi-threaded transmissions.
Curlopt_post
When enabled, a regular post request is sent with the type: application/x-www-form-urlencoded, just as the form was submitted.
Curlopt_put
Allow HTTP to send files when enabled, you must set both Curlopt_infile and Curlopt_infilesize
Curlopt_returntransfer
The information obtained by CURL_EXEC () is returned in the form of a file stream, rather than as a direct output.
Curlopt_ssl_verifypeer
FALSE to stop CURL from verifying the peer ' s certificate. Alternate certificates to verify against can is specified with the Curlopt_cainfo option or a certificate directory can is Specified with the Curlopt_capath option. Curlopt_ssl_verifyhost may also need to be TRUE or FALSE if curlopt_ssl_verifypeer are 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 an ASCII mode for FTP transfers. For LDAP, it retrieves the data in plain text instead of HTML. On Windows systems, it won't set STDOUT to binary mode.
Curlopt_unrestricted_auth
The user name and password information is continuously appended to multiple locations in the header generated by using curlopt_followlocation, even if the domain name has changed.
Curlopt_upload
Allow file transfer when enabled
Curlopt_verbose
All information is reported when enabled and stored in stderr or specified curlopt_stderr
Curlopt_buffersize
Each time the retrieved data is read into the cache size, the value is filled every time.
Curlopt_closepolicy
Not curlclosepolicy_least_recently_used is curlclosepolicy_oldest, there are three other, but Curl is not supported for the time being.
Curlopt_connecttimeout
The time to wait before initiating the connection, and if set to 0, do not wait.
Curlopt_dns_cache_timeout
Sets the time to save DNS information in memory by default of 120 seconds.
Curlopt_ftpsslauth
The FTP authentication method (when is activated): Curlftpauth_ssl (try SSL first), Curlftpauth_tls (try TLS first), or CU Rlftpauth_default (let CURL decide).
Curlopt_http_version
Set Curl to use the HTTP protocol, Curl_http_version_none (let CURL himself judge), Curl_http_version_1_0 (http/1.0), Curl_http_version_1_1 (http/ 1.1)
Curlopt_httpauth
The optional values for the HTTP authentication method used are: Curlauth_basic,curlauth_digest,curlauth_gssnegotiate,curlauth_ntlm,curlauth_any,curlauth_ Anysafe, you can use the "|" operator to separate multiple values, curl allows the server to select one of the best supported values, Curlauth_any equivalent to Curlauth_basic | Curlauth_digest | Curlauth_gssnegotiate | Curlauth_ntlm,curlauth_anysafe equivalent to Curlauth_digest | Curlauth_gssnegotiate | Curlauth_ntlm
Curlopt_infilesize
Set the size of the upload file
Curlopt_low_speed_limit
When the transfer speed is less than Curlopt_low_speed_limit, PHP determines whether the transmission is canceled because it is too slow, depending on the curlopt_low_speed_time.
Curlopt_low_speed_time
The number of seconds the transfer should is below Curlopt_low_speed_limit for PHP to consider the transfer too slow and a Bort.
When the transfer speed is less than Curlopt_low_speed_limit, PHP determines whether the transmission is canceled because it is too slow, depending on the curlopt_low_speed_time.
Curlopt_maxconnects
The maximum number of connections allowed, over the Curlopt_closepolicy, determines which connections should be stopped
Curlopt_maxredirs
Specify the maximum number of HTTP redirects that are used with curlopt_followlocation.
Curlopt_port
An optional amount to specify the connection port
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 is currently supported.
Curlopt_proxyport
The port number of the proxy to connect to. This port number can also is set in Curlopt_proxy.
Curlopt_proxytype
Either curlproxy_http (default) or CURLPROXY_SOCKS5.
Curlopt_resume_from
Pass a byte offset (used to resume a breakpoint) when the transfer is resumed
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 would try to determine the itself, although in some cases this must is set manually.
Curlopt_timecondition
If edited after a time specified by Curlopt_timevalue, returns a page using Curl_timecond_ifmodsince, if it has not been modified, and Curlopt_header is true, returns a 304 not Modified "Header,curlopt_header is false, the curl_timecond_isunmodsince is used, and the default value is Curl_timecond_ifmodsince
Curlopt_timeout
Set the maximum number of seconds that curl is allowed to execute
Curlopt_timevalue
Set the timestamp used by a curlopt_timecondition, using curl_timecond_ifmodsince in the default state
Curlopt_cainfo
The name of a file holding one or more certificates to verify the peer with. This is makes sense when used in combination with Curlopt_ssl_verifypeer.
Curlopt_capath
A directory that holds multiple CA certificates. Use the This option alongside Curlopt_ssl_verifypeer.
Curlopt_cookie
Set the contents of the "Set-cookie:" section of the HTTP request.
Curlopt_cookiefile
The name of the file containing the cookie information, which can be the header information in Netscape format or HTTP style.
Curlopt_cookiejar
The name of the file holding the 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 was useful for doing "DELETE" or other, and more obscure HTTP requests. Valid values is 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 the server supports the custom request method first.
Curlopt_egbsocket
Like Curlopt_random_file, except a filename to an Entropy gathering Daemon socket.
Curlopt_encoding
The contents of the "Accept-encoding:" section of the header are supported in the following encoding formats: "Identity", "deflate", "gzip". If set to an empty string, it means that all encoding formats are supported
Curlopt_ftpport
The value which would 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 is a plain IP address, a hostname, a network interface name (under Unix), or just a plain '-' to use the SY Stems default IP address.
Curlopt_interface
The name used in the external network interface, which can be an interface name, IP, or host name.
Curlopt_krb4level
KRB4 (Kerberos 4) Security level setting, can be one of several values: "Clear", "safe", "confidential", "private". The default value is "Private", which is set to NULL when KRB4 is disabled, and now KRB4 security can only be used in FTP transport.
Curlopt_postfields
The "POST" operation in HTTP. If you want to send a file, [email protected]
Curlopt_proxy
Setting up an HTTP proxy server through
Curlopt_proxyuserpwd
The user name and password in the format "[Username]:[password]" connected to the proxy server.
Curlopt_random_file
Set the file name of the random number seed used to hold SSL
Curlopt_range
Set the HTTP transmission range, you can set a transmission interval in the form of "X-y", if there are multiple HTTP transmissions, use commas to separate multiple values, such as: "X-y,n-m".
Curlopt_referer
Sets the value of the "Referer:" section in the header.
Curlopt_ssl_cipher_list
A List of ciphers to use for SSL. For example, Rc4-sha and TLSV1 is valid cipher lists.
Curlopt_sslcert
Pass a string containing a certificate in PEM format.
curlopt_sslcertpasswd
Pass a password that contains the required use of the Curlopt_sslcert certificate.
Curlopt_sslcerttype
The format of the certificate. Supported formats is "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 asymmetric 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 is "PEM" (default), "DER", and "ENG".
Curlopt_url
The URL address you need to get, or you can set it in PHP's Curl_init () function.
Curlopt_useragent
A string that contains a "user-agent" header in the HTTP request.
Curlopt_userpwd
Pass in a connection the user name and password required in the format: "[Username]:[password]".
Curlopt_http200aliases
Sets the response to HTTP 200, which is no longer handled as error, in the form of an array.
Curlopt_httpheader
Sets an array of contents to transfer in a header.
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.
Curlopt_file
Sets the location of the output file, the value is a resource type, and the default is stdout (browser).
Curlopt_infile
The file address to be read when uploading the file, the value is a resource type.
Curlopt_stderr
Sets an error output address, which is a resource type that supersedes the default stderr.
Curlopt_writeheader
Sets the file address to write the header portion of the content, and the value is a resource type.
Curlopt_headerfunction
Set a callback function that has two parameters, the first is the resource handle for curl, and the second is the header data for the output. The output of the header data must rely on this function to return the size of the data that has been written.
Curlopt_passwdfunction
Set a callback function with three parameters, the first one is the resource handle for curl, the second is a password prompt, and the third parameter is the maximum allowed for the password length. Returns the value of the password.
Curlopt_readfunction
Set a callback function with two parameters, the first is the resource handle for curl, and the second is the data to be read. Data reads must depend on this function. Returns the size of the read data, such as 0 or EOF.
Curlopt_writefunction
Set a callback function with two parameters, the first is the resource handle for curl, and the second is the data to be written. Data writes must depend on this function. Returns the exact size of the written data
The role of the Curl_copy_handle () function is to copy all the contents 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 function of the Curl_error () function is to return a string containing the current session error information.
The function of the Curl_errno () function is to return a numeric number that contains the current session error information.
The function of the Curl_multi_init () function is to initialize a curl batching handle resource.
The function of the Curl_multi_add_handle () function is to add a separate curl handle resource to the Curl batch session. The Curl_multi_add_handle () function has two parameters, the first parameter represents a curl batch handle resource, and the second parameter represents a separate curl handle resource.
The action of the Curl_multi_exec () function is to parse a curl batch handle, the Curl_multi_exec () function has two parameters, the first parameter represents a batch handle resource, the second argument is a reference value parameter, Represents the number of individual curl handle resources remaining to be processed.
The Curl_multi_remove_handle () function represents a handle resource removed from the Curl batch handle resource, the Curl_multi_remove_handle () function has two parameters, the first parameter represents a curl batch handle resource, The second parameter represents a separate curl handle resource.
The function of the Curl_multi_close () function is to close a batch handle resource.
?
$ch 1 = curl_init (), $ch 2 = Curl_init (), curl_setopt ($ch 1, Curlopt_url, "http://www.baidu.com/"), curl_setopt ($ch 1, Curlopt_header, 0); curl_setopt ($ch 2, Curlopt_url, "http://www.google.com/"); curl_setopt ($ch 2, Curlopt_header, 0); $ MH = Curl_multi_init (); Curl_multi_add_handle ($MH, $ch 1); Curl_multi_add_handle ($MH, $ch 2);d o {curl_multi_exec ($MH, $ Flag);} while ($flag > 0); Curl_multi_remove_handle ($