Php uses curl to simulate the collection page after logon. My homework today is to get product inventory from a website, but this website needs to be logged on. I used fsockopen to pass the entire header, and it was useless. I had to turn to curl for help. Note that I received my homework today to get product inventory from a website, but this website needs to be logged on. I used fsockopen to pass the entire header, and I had to turn to curl for help.
The following describes how to enable the curl module:
(1) copy libeay32.dll and ssleay32.dll from the php directory to the windows directory.
(2) open php. ini, find "extension_dir = xxxxx", and check that the php_curl.dll file is in the file directory.
(3) in the same way as php. ini, find "extension = php_curl.dll" and confirm that it is not commented out (no ';' above ';').
(4) restart apache. if curl_init () is used and an error message is displayed in the statement, the installation is successful.
The code is as follows:
$ Curl = curl_init ();
$ Cookie_jar = tempnam ('./tmp', 'cooker ');
Curl_setopt ($ curl, CURLOPT_URL, 'http: // B2B .bookuu.com/ B2B _club/checkUser.jsp'); // enter the logon processing interface here.
Curl_setopt ($ curl, CURLOPT_POST, 1 );
$ Request = 'User = xxx & password = xxx ';
Curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ request); // transfers data
Curl_setopt ($ curl, CURLOPT_COOKIEJAR, $ cookie_jar); // Save the returned cookie information in the $ cookie_jar file.
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); // Sets whether the returned data is automatically displayed.
Curl_setopt ($ curl, CURLOPT_HEADER, false); // you can specify whether the header information is displayed.
Curl_setopt ($ curl, CURLOPT_NOBODY, false); // you can specify whether to output the page content.
Curl_exec ($ curl); // return the result
Curl_close ($ curl); // Close
$ Curl2 = curl_init ();
Curl_setopt ($ curl2, CURLOPT_URL, 'http: // B2B .bookuu.com/search/ B2B _zxsm_new.jsp'); // The page on which to obtain information 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 );
Bytes. Additional description 1...