Php uses curl to simulate the collection page after logon. example _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.