Phpcurl_init function usage _ PHP Tutorial

Source: Internet
Author: User
Usage of the phpcurl_init function. Using the PHP cURL library, you can easily and effectively capture webpages. You only need to run a script and analyze the web page you crawled, then, you can get the desired PHP cURL library in the form of a program, which can easily and effectively capture webpages. You only need to run a script, analyze the web page you crawled, and then you can get the data you want as a program.

Whether you want to retrieve part of the data from a link or an XML file and import it to the database, you may simply get the webpage content, cURL is a powerful PHP library. CURL Library Function in PHP) curl_close-close a curl session curl_copy_handle-copy all content and parameters of a curl connection resource curl_errno-returns a number containing the current session error message curl_error-returns a message containing the current session error message string curl_exec-execute a curl session curl_getinfo-get the information of a curl connection resource handle curl_init-initialize a curl session curl_multi_add_handle-add a separate curl handle resource curl_multi_close to the curl batch processing session-close one batch handle resource curl_multi_exec-parses a curl batch handle curl_multi_getcontent-returns the obtained output text stream curl_multi_ I Nfo_read-Get the transmission information of the currently resolved curl curl_multi_init-initialize a curl batch processing handle resource curl_multi_remove_handle-remove a handle resource in the curl batch processing handle curl_multi_select-Get all the sockets associated the cURL extension, which can then be "selected" curl_setopt_array-set the session parameter curl_setopt for a curl in the form of an array-set the session parameter curl_version for a curl-get the curl-related version information curl_init () the function initializes a curl session. the unique parameter of the curl_init () function is optional, indicating a url address. The role of the curl_exec () function is to execute a curl session. the unique parameter is the handle returned by the curl_init () function. The function curl_close () is used to close a curl session. the only parameter is the handle returned by the curl_init () function. Example 1: Basic example code: Example 2: POST data sendSMS. php can accept two form fields: phone number and text message content. The POST data code is as follows: Example 3: Use the proxy server code as follows: Example 4: simulate Curl login to simulate login to the discuz program, suitable for DZ7.0, change username to your user name, and change userpass to your password. the code for simulating login to discuz using Curl is as follows: /I ', $ contents, $ matches); if (! Empty ($ matches) {$ formhash = $ matches [1];} else {die ('Not found the forumhash. ');} // POST the data to obtain the COOKIE $ cookie_file = dirname (_ FILE __). '/cookie.txt'; // $ cookie_file = tempnam ('/tmp'); $ ch = curl_init ($ login_url); curl_setopt ($ ch, CURLOPT_HEADER, 0 ); curl_setopt ($ ch, batch, 1); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_fields); curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookie_file); curl_exec ($ ch); curl_close ($ ch ); // Obtain the page content that requires logon with the COOKIE obtained above $ ch = curl_init ($ get_url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 0); curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookie_file); $ contents = curl_exec ($ ch); curl_close ($ ch); var_dump ($ contents );

Bytes. You only need to run a script, analyze the web page you crawled, and then you can get what you want in the form of a program...

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.