Extension of PHP to CURL

  • 2021-07-01 07:02:49
  • OfStack

Functions implemented:

1. Realize remote acquisition and collection of content

2. Upload and download FTP of PHP web page version

3. Realize simulated login: Go to a mail system, and curl can simulate cookies

4. Realize interface docking (API), data transmission, etc.: Send short messages through one platform, grab and transmit the transmitted information.

5. Realize the simulation of Cookie, etc.: Only when you log in can you operate some attributes.

How to use CURL features:

By default, adding PHP does not support CURL. This function needs to be turned on in php. ini

; extension=php_curl. dll preceding semicolon removed

The first step in the whole operation is to initialize with the cur_init () function


$curl = curl_init( ' www.ofstack.com')

2. Use the curl_setopt () function to set the options.

3. After setting, execute transaction curl_exec ($curl);

4 Finally turn off curl_close ();

Use PHP CURL to realize transmission and acquisition function (post transmission mode): obtain remote web page data


$user = "admin";
$pass = "admin";
$curlPost = "user=$user&pass=$pass";
$ch = curl_init(); // Initialization 1 A CURL Object 
curl_setopt($ch, CURLOPT_URL, "http://localhost/edu/login.php");
// Set what you need to grab URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
// Settings curl Parameter, which requires whether the result is output to the screen, is true Do not return to the web page when 
 Suppose the above 0 Change to 1 If so, then the next one $data You need to echo1 Under. 
curl_setopt($ch, CURLOPT_POST, 1);
//post Submit 
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);
// Run curl, Request 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 it is hidden by the browser.

============================================================================

curl simulated landing

Simulated login: Is not to log in to the php100 forum, can also view the corresponding information.

Analyze the login field-- > Keep cookie after landing- > Read cookie and jump to the related page-- > Grasp number

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

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

3. Go to the relevant pages to get the required content

tempname Create 1 Temporary File

The tempnam () function creates a temporary file with only one file name. If successful, the function returns a new temporary file name. If it fails, false is returned.

tempnam(dir,prefix)

Parameter description

dir required. Specify the directory where temporary files are created.

prefix required. Specifies the beginning of the file name.

Equivalent to, fopen fwirte fclose

It can return 1 Boolean value. Using a third party to log in to your QQ, msn is dangerous because it can record your login status and grab your username and password.

Log in to the PHP100 forum using CURL simulation

1. Analyze the field name and number of input box required for login

2. Save the number of member gold coins obtained after cookie simulated login

Code:


// Initialization 1 A  cURL  Object 
$curl = curl_init();
// Set what you need to grab URL
curl_setopt($curl, CURLOPT_URL, " http://www.baidu.com ");
// Settings cURL  Parameter, whether the result should be saved to a string or output to the screen. 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);
// Run cURL Request Web page 
$data = curl_exec($curl);
// Shut down 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);
?>


Related articles: