PHP Curl Instance + detailed, phpcurl_php tutorial

Source: Internet
Author: User
Tags http cookie urlencode

PHP Curl Instance + detailed, Phpcurl


Directly on 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 appropriate optionscurl_setopt ($ch, Curlopt_url,$url); curl_setopt ($ch, Curlopt_header, 0); curl_setopt ($ch, Curlopt_returntransfer, 1);//important! Need to fetch the specific contents of the return value to fill in $json=curl_exec ($ch); //executes a given curl session. This function should be called after initializing a curl session and all of the options are set. $json =curl_getinfo ($ch);//Gets information about the last transmission. $json =curl_multi_getcontent ($ch); $json=curl_multi_getcontent ($ch) ; $result=json_decode ($json,true);//returns the text stream of the obtained output if Curlopt_returntransfer is set $arr=$result[' Result '] [' Location ']; //Var_dump ($result); Echo $address. ": Longitude:".$arr[' LNG ']. ", Latitude:".$arr[' Lat '].

"; //Turn off the Curl resource and release the system resourcesCurl_close ($ch);

/*    Curl_close-closes a Curl session curl_copy_handle-copies a curl handle and all its options curl_errno-returns the last error number curl_error-returns a protection for the current session Near the wrong string curl_escape-uses a URL to encode the given string curl_exec-perform a curl session curl_file_create-create a Curlfile object Curl_getinf O gets information about a Curl connection resource handle curl_init-Initializes a curl session curl_multi_add_handle-adds a separate curl handle to the Curl batch session curl_multi_close-off Closes a set of curl handles curl_multi_exec-the child connection that runs the current curl handle curl_multi_getcontent-If Curlopt_returntransfer is set, the text stream of the obtained output is returned cur L_multi_info_read-Gets the associated transport information for the currently resolved Curl curl_multi_init-returns a new Curl batch handle curl_multi_remove_handle-removes a curl batch handle in the resource Handle resource curl_multi_select-waits for active connections in all Curl batches curl_multi_setopt-to set an option for Curl parallel processing Curl_multi_strerror-return str ING describing error code curl_pause-pause and unpause a connection curl_reset-reset all options of a libcurl se  Ssion handle curl_setopt_array-for Curl transfer session bulk setup options curl_setopt-set a curl transfer option curl_share_close-close a curl share Handle curl_share_inIt-initialize a curl share handle curl_share_setopt-set an option for a curl share handle. Curl_strerror-return string describing the given error code curl_unescape-decodes the given URL-encoded string curl_version-gets curl     Version information*//*The Official Handbook of the curl_setopt ();        $options = Array (Curlopt_returntransfer = true,//return page Curlopt_header = False, Do not return head Curlopt_followlocation = True,//follow redirect curlopt_encoding = "",//Place        Code curlopt_useragent = "Spider",//Who I am Curlopt_autoreferer = true,//Set reference page redirection Curlopt_connecttimeout = 120,//connection Timeout curlopt_timeout = 120,//Response time-out CU Rlopt_maxredirs = 10,//stop after 10 redirect Curlopt_post = 1,//I send POST data C Urlopt_postfields = $curl _data,//requests sent Curlopt_ssl_verifyhost = 0,//Do not verify SSL curlop    T_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);*//*

This is what the rest of the network finds.
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 the file you are uploading. *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 Curlopt_infile and Curlopt_infilEsize option. *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 for 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 placed the transfer to, 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.*/

http://www.bkjia.com/PHPjc/1120387.html www.bkjia.com true http://www.bkjia.com/PHPjc/1120387.html techarticle PHP Curl Instance + detailed, Phpcurl directly on the instance? PHP//Create a new curl resource $ch = Curl_init ();//URL transcoding for special characters such as Chinese = urlencode ($address); $ur ...

  • Related Article

    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.