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?