Get the App
SLTechnology News&Howtos  ›  Development  › 

Php uses curl to simulate how to collect pages after login

Shulou Source: shulou.com Published: 2022-06-03 07:40:16 09月15日 Update

This article introduces the knowledge of "php using curl to simulate the method of collecting pages after logging in". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

The homework I received today is to get inventory from a website, but this website needs to be logged in. I used fsockopen to pass the entire header header, which is useless. I can only resort to curl.

Let's talk about how to open the curl module:

(1)Copy: libeay32.dll, ssleay32.dll from php directory to windows directory.

(2)Open php.ini, look for "extension_dir = xxxxx", and make sure there is php_curl.dll in the following file directory.

(3)Also php.ini, look for "extension=php_curl.dll" and make sure it is not commented (no ';' in front).

(4)Restart apache, if the curl_init(); statement appears error prompt, then the installation is not successful.

The copy code is as follows:

$curl = curl_init();

$cookie_jar = tempnam('./ tmp','cookie');

curl_setopt($curl, CURLOPT_URL,'http://b2b.bookuu.com/b2b_club/checkUser.jsp');//Write the login interface here

curl_setopt($curl, CURLOPT_POST, 1);

$request = 'user=xxx&password=xxx';

curl_setopt($curl, CURLOPT_POSTFIELDS, $request);//pass data

curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);//Save returned cookie information in $cookie_jar file

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//Sets whether the returned data is automatically displayed

curl_setopt($curl, CURLOPT_HEADER, false);//Sets whether header information is displayed

curl_setopt($curl, CURLOPT_NOBODY, false);//Set whether to output page content

curl_exec($curl);

curl_close($curl);

$curl2 = curl_init();

curl_setopt($curl2, CURLOPT_URL, 'http://b2b.bookuu.com/search/b2b_zxsm_new.jsp');//Which page do you want to get information from after login

curl_setopt($curl2, CURLOPT_HEADER, false);

curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl2, CURLOPT_COOKIEFILE, $cookie_jar);

$content = curl_exec($curl2);

"php use curl simulation login after the collection of page method tutorial" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Pages login content files directories websites tutorials methods code information data more knowledge output practical successful successful learning next methods homework Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Microsoft MariaDB macOS Shulou Tech Info