php USES curl to simulate the collection of pages after login

  • 2020-11-03 22:03:53
  • OfStack

The lesson I received today was to get the inventory of goods from a website, but the website needed to be logged in. I passed the whole header header with fsockopen to no effect, so I had to turn to curl for help.
The following is the opening method of curl module:
(1) Copy from php directory: libeay32.dll, ES10en32.ES11en to windows.
(2) Open php.ini and look for "extension_dir = xxxxx". Confirm that the php_curl.dll file is in the following file directory.
(3) Also php.ini, look for "extension= php_curl.dll" to make sure it is not commented (not before '; ').
(4) Restart apache, if curl_init() is used; Statement error indicates that the installation was not successful.


$curl = curl_init();
$cookie_jar = tempnam('./tmp','cookie');
curl_setopt($curl, CURLOPT_URL,'http://b2b.bookuu.com/b2b_club/checkUser.jsp');// Here's the interface to handle login 
curl_setopt($curl, CURLOPT_POST, 1);
$request = 'user=xxx&password=xxx';
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);// the   Pass data 
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);//  I'm going to return cookie Information is saved in $cookie_jar In the file 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);// Set to return to   Whether the data is displayed automatically 
curl_setopt($curl, CURLOPT_HEADER, false);// Sets whether to display header letters   Interest rates 
curl_setopt($curl, CURLOPT_NOBODY, false);// Sets whether to output the page   content 
curl_exec($curl);// Returns the result 
curl_close($curl); // Shut down 
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_URL, 'http://b2b.bookuu.com/search/b2b_zxsm_new.jsp');// Which page to get information from after logging in 
curl_setopt($curl2, CURLOPT_HEADER, false);
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl2, CURLOPT_COOKIEFILE, $cookie_jar);
$content = curl_exec($curl2);


Related articles: