Home >Backend Development >PHP Tutorial >Example of php using curl to simulate logging in and collecting pages_PHP tutorial
The homework I received today is to obtain product inventory from a website, but this website requires login. I used fsockopen to pass the entire header to no avail, so I had to resort to curl.
By the way, let me talk about how to open the curl module:
(1) Copy: libeay32.dll, ssleay32.dll from the php directory to the windows directory.
(2) Open php.ini, search for "extension_dir = xxxxx", and confirm that there is a php_curl.dll file in the following file directory.
(3) The same is php.ini, look for "extension=php_curl.dll" and confirm that it is not commented (there is no ';' in front).
(4) Restart apache. If an error message appears when using the curl_init(); statement, it means the installation was not successful.
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_URL, 'http://b2b.bookuu.com/search/b2b_zxsm_new.jsp');//Which page should you 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) ;