How PHP Expands Curl

Source: Internet
Author: User
Curl is a file transfer tool that works by using URL syntax to love command-line mode. It supports many protocols. It supports authentication functions. More complex transfer functions are commonly implemented in PHP.

The functions implemented:

1. Realize remote acquisition and acquisition of content

2, the implementation of PHP Web version of the FTP upload download

3, realize the simulation landing: Go to a mail system, curl can simulate cookies

4, to achieve interface docking (API), data transmission, such as: through a platform to send text messages, crawling and transmitting the information transmitted.

5, the realization of analog cookies, etc.: the state of landing can be manipulated some properties.

How to use the Curl feature :

By default PHP does not support curl, you need to turn on this feature in php.ini

The semicolon in front of the Extension=php_curl.dll is removed

1 The first step during the entire operation is to initialize with the Cur_init () function.

?

$curl = Curl_init (' www.php.cn ')

3. After setting, perform the transaction curl_exec ($curl); 2. Set the option with the curl_setopt () function.

4 finally close curl_close ();

Use PHP curl for transfer and capture (post transfer): Get Remote Web page data

$user = "admin"; $pass = "admin"; $curlPost = "user= $user &pass= $pass"; $ch = Curl_init (); Initialize a Curl object curl_setopt ($ch, Curlopt_url, "http://localhost/edu/login.php");//Set the urlcurl_setopt you need to crawl ($ch, Curlopt_returntransfer, 0);//Set the curl parameter, which requires the result to be output to the screen, true when it is not returned to the Web page if the above 0 is changed to 1, then the next $data need to echo. curl_setopt ($ch, Curlopt_post, 1);//post Submit curl_setopt ($ch, Curlopt_postfields, $curlPost); $data = Curl_exec ($ch);// Run Curl and request the Web page. Curl_close ($ch); [/code]

Realize the most basic part of remote simulation landing.

Curl also needs to configure the user name and password, but is hidden by the browser.

============================================================================\

Curl Simulation Login

Analog landing: is not landing to the PHP100 forum, you can also see the corresponding information.

Analyze login Field---> Leave cookie after Login--read cookie and jump to related page--crawl count

1. Create a file after the login to save the cookie content

2. Simulate user login status by reading the generated cookie content

3, to the relevant page to obtain the required content

Tempname Creating a temporary file

The Tempnam () function creates a temporary file with a unique file name. If successful, the function returns a new temporary file name. If it fails, it returns false.

Tempnam (Dir,prefix)

Parameter description

Dir required. Specifies the directory where temporary files are created.

Prefix required. Specifies the beginning of the file name.

Equivalent, fopen fwirte fclose

It can return a Boolean value. Using a third party to login to your QQ, MSN is very dangerous, because it can record your login status, crawl your user name and password.

Login to the PHP100 forum using Curl emulation

1, analyze the login required input box field name and the number of fields required

2, save the cookie simulation login to obtain the number of member coins

Code:

//initialize a CURL object $curl = Curl_init ();//Set the urlcurl_setopt you need to crawl ($curl, Curlopt_url , "http://www.baidu.com");//sets the curl parameter, which requires the result to be saved to a string or output to the screen. curl_setopt ($curl, Curlopt_returntransfer, 0);//Run Curl, request page $data = curl_exec ($curl);//close URL request curl_close ($curl); user = "Admin"; $pass = "admin100"; $curlPost = "user= $user &pass= $pass"; $ch = Curl_init (); curl_setopt ($ch, Curlopt_ URL, "http://localhost/curl/login.php"); curl_setopt ($ch, Curlopt_returntransfer, 0); curl_setopt ($ch, Curlopt_post, 1); curl_setopt ($ch, Curlopt_postfields, $curlPost), $data = Curl_exec ($ch); Curl_close ($ch);? >if ($_post[' user ']== "admin") {echo "";} else{echo "";} Print_r ($_post);? 

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.