Application example of the PHPCURL Library-PHP Tutorial

Source: Internet
Author: User
Application example of the PHPCURL Library. 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.

Common functions of the CURL Library Function in PHP are as follows:

  • Curl_close-close a curl session
  • Curl_copy_handle-copy all content and parameters of a curl connection resource
  • Curl_errno-a number containing the current session error message is returned.
  • Curl_error-returns a string containing the current session error message.
  • Curl_exec-execute a curl session
  • Curl_getinfo-obtains the information of a curl connection resource handle.
  • Curl_init-initialize a curl session
  • Curl_multi_add_handle-add a separate curl handle resource to the curl batch processing session
  • Curl_multi_close-close a batch processing handle resource
  • Curl_multi_exec-parse a curl batch handle
  • Curl_multi_getcontent-return the obtained output text stream
  • Curl_multi_info_read-obtains 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 from the curl batch processing handle.
  • Curl_multi_select-Get all the sockets associated with the cURL extension, which can then be "selected"
  • Curl_setopt_array-set session parameters for a curl in the form of an array
  • Curl_setopt-set session parameters for a curl
  • Curl_version-obtain curl-related version information
  • The function curl_init () 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.
Basic example
 
POST data

Two form fields are accepted. one is the phone number and the other is the text message content.

 
Use proxy server
 
Simulated logon

Simulate login to the discuz program.

 /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, CURLOPT_RETURNTRANSFER, 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, cursor, 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.