Php curl instance + explanation, phpcurl

Source: Internet
Author: User
Tags http cookie

Php curl instance + explanation, phpcurl

Directly mount the instance

<? Php // create a new cURL resource $ ch = curl_init ();
// Url transcoding for special characters such as Chinese $ aurl = urlencode ($ address); $ url = "http://api.map.baidu.com/geocoder/v2? Address = ". $ aurl. "& output = json & ak = {Your api}"; // set the URL and the corresponding options curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // important! Specify $ json = curl_exec ($ ch) to capture the returned value. // execute the specified cURL session. This function should be called after a cURL session is initialized and all the options are set. // $ Json = curl_getinfo ($ ch); // obtain the last transmitted information. // $ Json = curl_multi_getcontent ($ ch); $ result = json_decode ($ json, true); // If CURLOPT_RETURNTRANSFER is set, returns the obtained output text stream $ arr = $ result ['result'] ['location']; // var_dump ($ result); echo $ address. ": longitude :". $ arr ['lng ']. ", latitude :". $ arr ['lat']. "<br>"; // closes the cURL resource and releases the system resource curl_close ($ ch );

 

/* Curl_close-close a cURL session curl_copy_handle-copy a cURL handle and all its options curl_errno-return the last error code curl_error-return a string curl_escape that protects the last error of the current session -Use the URL-encoded string curl_exec-execute a cURL session curl_file_create-create a CURLFile object curl_getinfo-obtain the information of a cURL connection resource handle curl_init-initialize a cURL session curl_multi_add_handle-batch to the curl add a separate curl handle to the processing session curl_multi_close-close a group of cURL handles curl_multi_exec-run the subconnection of the current cURL handle curl_multi_getcontent-If CURLOPT_RETURNTRANSFER is set, return the obtained output text stream curl_multi_info_read-obtain the transmitted information of the currently resolved cURL curl_multi_init-return a new cURL batch processing handle curl_multi_remove_handle-remove a handle resource from the curl batch processing handle curl_multi_select-wait for all active connections in the cURL batch processing curl_multi_setopt-set an option curl_multi_strerror-Return string describing error code curl_pause-Pause and unpause a connection curl_reset-Reset all options of libcurl session handle-Set the option curl_setopt for the cURL transport session batch-Set a cURL transport option curl_transport _close-Close a cURL share handle curl_assist_init-Initialize a cURL share handle curl_assist_setopt-Set an option for cURL share handle. curl_strerror-Return string describing the given error code curl_unescape-decodes the given URL-encoded string curl_version-retrieves cURL version information * // * column curl_setopt () in the official manual (); $ options = array (CURLOPT_RETURNTRANSFER => true, // return the webpage CURLOPT_HEADER => false, // do not return the header CURLOPT_FOLLOWLOCATION => true, // follow the redirection CURLOPT_ENCODING => "", // Process Code CURLOPT_USERAGENT => "spider", // who is CURLOPT_AUTOREFERER => true, // set the reference page redirection CURLOPT_CONNECTTIMEOUT => 120, // connection timeout CURLOPT_TIMEOUT => 120, // response timeout CURLOPT_MAXREDIRS => 10, // 10 redirection CURLOPT_POST => 1 after stopping, // I send post data CURLOPT_POSTFIELDS => $ curl_data, // send the request CURLOPT_SSL_VERIFYHOST => 0, // do not verify ssl CURLOPT_SSL_VERIFYPEER => false, // CURLOPT_VERBOSE => 1 //); $ ch = curl_init ($ url ); curl_setopt_array ($ ch, $ options); $ content = curl_exec ($ ch); $ err = curl_errno ($ ch); $ errmsg = curl_error ($ ch ); $ header = curl_getinfo ($ ch); curl_close ($ ch );*//*

Here is the relevant information found in other parts of the network.
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 value of the following options will be used as a 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 you upload. * 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: sets this option to upload a file over HTTP as a non-zero value. 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 value of the following options will be used as a string: * CURLOPT_URL: This is 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 format of [username]: [password] to connect to PHP. * 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: transmits a string of 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 includes 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. */

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.