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.
Copy code The 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);//Transfer data
curl_setopt($curl, CURLOPT_COOKIEJAR , $cookie_jar);//Save the returned cookie information in the $cookie_jar file
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//Set whether the returned data is automatically displayed
curl_setopt($curl, CURLOPT_HEADER, false);//Set whether to display header information
curl_setopt($curl, CURLOPT_NOBODY, false);//Set whether to output page content
curl_exec($curl);//Return results
curl_close($curl); //Close
$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) ;
http://www.bkjia.com/PHPjc/825018.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825018.htmlTechArticleThe homework I received today is to obtain product inventory from a website, but this website requires login, I passed it using fsockopen The entire header is useless, so we can only resort to curl. By the way...