Phpcurl simulates logon to Baidu homepage

Source: Internet
Author: User
Phpcurl simulates the following code to log on to the Baidu homepage:
 */$ Post_fields = array (); $ post_fields = preg_data ($ contents, 'aid ', $ post_fields); $ post_fields = preg_data ($ contents, 'isphone ', $ post_fields); $ post_fields ['mem _ pass'] = 'on'; // The post data array remembers my logon status $ post_fields = preg_data ($ contents, 'More _ param', $ post_fields); $ post_fields = preg_data ($ contents, 'need _ coin ', $ post_fields); $ post_fields = preg_data ($ contents, 'Need _ pay', $ post_fields); $ post_fields = preg_data ($ contents, 'next _ target', $ post_fields); $ post_fields ['password'] = 'password '; // The post data array remembers my logon status $ post_fields = preg_data ($ contents, 'pay _ method', $ post_fields); $ post_fields = preg_data ($ contents, 'PSP _ TT', $ post_fields); $ post_fields = preg_data ($ contents, 'Return _ method', $ post_fields); $ post_fields = preg_data ($ contents, 'return _ type', $ post_fields); $ post_fields = preg_data2 ($ contents, 'safeflg', $ post_fields); $ post_fields = preg_data ($ contents, 'skip _ OK ', $ post_fields); $ post_fields = preg_data ($ contents, 'tpl', $ post_fields); $ post_fields = preg_data ($ contents, 'tpl _ OK ', $ post_fields ); $ post_fields ['u'] =' http://www.baidu.com/ '; $ Post_fields ['username'] = 'username'; // The post data array remembers my logon status $ post_fields ['verifycode'] = ''; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ($ ch, CURLOPT_POST, 1); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_fields); curl_setopt ($ ch, expires, $ cookdir); curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1 ;. net clr 1.1.4322 ;. net clr 2.0.50727) "); curl_setopt ($ ch, CURLOPT_REFERER ," https://passport.baidu.com/?login&tpl=mn "); Curl_exec ($ ch); curl_close ($ ch); $ url =" http://www.baidu.com/ "; $ Ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookdir); curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1 ;. net clr 1.1.4322 ;. net clr 2.0.50727) "); curl_setopt ($ ch, CURLOPT_REFERER ," http://www.baidu.com/ N "); $ contents = curl_exec ($ ch); print_r ($ contents); die; curl_close ($ ch); exit; function preg_data ($ source, $ chr, $ array) {preg_match ('/
 
  
/I ', $ source, $ matches); if (! Empty ($ matches) {$ a = $ matches [1];} else {die ('Not found '. $ chr. '. ') ;}$ array [$ chr] = $ a; return $ array;} function preg_data2 ($ source, $ chr, $ array) {preg_match ('/
  
   
/I ', $ source, $ matches); if (! Empty ($ matches) {$ a = $ matches [1];} else {die ('Not found '. $ chr. '. ') ;}$ array [$ chr] = $ a; return $ array ;}?>
  
 


You cannot access the logon page.


Reply to discussion (solution)

The website may have switched

Set CURLOPT_FOLLOWLOCATION to TRUE.

Set CURLOPT_FOLLOWLOCATION to TRUE.



This does not seem to work.

What's wrong !!!

I have already written python and c # versions.
Wait for me to get another php version, simulate logon to Baidu, and show it to you.

Has the landlord solved the problem?

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.