PHPcurl simulates login to obtain cookie

Source: Internet
Author: User
PHPcurl simulates login to obtain cookies. Cainiao learns to use PHP & nbsp; curl to simulate login. when we use the following code to log on to www.xiaomi.com, the login will fail. The cookie is obtained. Please help me solve the problem. PHP curl simulates login to obtain cookie for help
Cainiao learns to use PHP curl to simulate login. when the following code is used to successfully log on to www.xiaomi.com, the login will fail. The cookie is obtained. Please help me solve the problem. Think about what you can't do at night without income!

$ Cookie_file = tempnam ('./temp', 'cooker ');
$ Login_url = 'https: // account.xiaomi.com/pass/serviceloginauth ';
$ Post = 'User & pwd = & sid = eshop & callback = http % 3A % 2F % 2Forder.xiaomi.com % 2 Flogin % 2 Fcallback % 3 Ffollowup % 3 Dhttp % 253A % 252F % 252Fwww.xiaomi.com % 252F % 26 sign % percent % 2C % 2C & _ sign = f % 2FKB8SAfmaLZ0s28kcLtBSmZlEM % 3D & _ json = true' // remove the post account and password from unnecessary troubles

$ Ch = $ curl = curl_init ($ login_url );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 0 );
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookie_file );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post );
Curl_exec ($ ch );
Curl_close ($ ch );

$ Url = "http://www.xiaomi.com/index.php ";
$ Ch = curl_init ($ url );
Curl_setopt ($ ch, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 0 );
Curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookie_file );
$ Contents = curl_exec ($ ch );
Curl_close ($ ch );


?>

Share:
------ Solution --------------------
 
  






Account name error


Enter account name









Enter password



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.