PHP simulated login problems I read a series of articles on the Internet to simulate the human network login, which is needed now, but what is the cause of TheURLhasmovedhere. Thank you. the code is as follows: PHPcode $ login_url = 'http: // passport. ren PHP simulated logon error
I read a series of articles on The Internet to simulate human login, which is exactly what I need now, but why does "The URL has moved here" appear. Thank you. the code is as follows:
PHP code
$ Login_url =' http://passport.renren.com/PLogin.do '; $ Post_fields ['email'] = 'XXX @ gmail.com '; $ post_fields ['password'] = 'XXX'; $ post_fields ['originurl'] =' http://www.renren.com/indexcon '; $ Post_fields ['domain'] = 'renren. com '; // The cookie file is stored in the temp folder of the website root directory $ cookie_file = tempnam ('. /temp ', 'cookies'); $ ch = curl_init ($ login_url); curl_setopt ($ ch, CURLOPT_USERAGENT, 'mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv: 1.9.1.5) Gecko/20091102 Firefox/3.5.5 '); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ($ ch, batch, 1); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ ch, CURLOPT_AUTOREFERER, 1); curl_setopt ($ ch, CURLOPT_POST, 1 ); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_fields); curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookie_file); curl_exec ($ ch); curl_close ($ ch); // Carries the cookie file, visit Renren homepage $ send_url =' http://home.renren.com/Home.do '; $ Ch = curl_init ($ send_url); curl_setopt ($ ch, CURLOPT_HEADER, 0); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ cookie_file); $ contents = curl_exec ($ ch); curl_close ($ ch); // clear the cookie file unlink ($ cookie_file ); // output the content of the Renren homepage print_r ($ contents );
------ Solution --------------------
Paste the following content.
In The past two days, The simulated browser submits The login form. after The submission is complete, The URL has movedhere ..
Each time, you need to click connect to open the homepage after logon. This is not what I want.
I read the description again and see the parameter-L.
-L/-- location Follow Location: hints (H)
-- Location-trusted Follow Location: and send auth to other hosts (H)
This is the key to the problem:
Curl -- output ". /rr.html "-- dump-header" d_cookie01 "-- cookie-jar" c_cookie01 "-- create-dirs -- location -- data" email = test & password = test & autoLogin = ture & origURL = & domain = renren.com & formName = & method = & isplogin = true & submit = login "http://www.renren.com/PLogin.do
After logging on to wowowo, the home page is downloaded !!
Check d_cookie01 carefully (including content from c_cookie01, but -- cookie-jar is more concise ).
Location: http://www.renren.com/callback.do? T = 9d5201d04d44156fb070037e9493f5fd3 & origURL = http % 3A % 2F % 2Fwww.renren.com % 2FHome. do & needNotify = false
It turns out that you still need to jump after submitting the login form each time, while-L follows the jump link.
We can also do this in two steps:
1. submit the form and save the returned cookie.
Curl -- output ". /rr.html "-- dump-header" d_cookie01 "-- data" email = test & password = test & autoLogin = ture & origURL = & domain = renren.com & formName = & method = & isplogin = true & submit = login "http://www.renren.com/PLogin.do
2. locate the location in d_cookie01 and submit the cookie and location together.
Curl -- output "./rr.html" -- dump-header "d_cookie01" -- location http://www.renren.com/callback.do? T = 9d5201d04d44156fb070037e9493f5fd3 & origURL = http % 3A % 2F % 2Fwww.renren.com % 2FHome. do & needNotify = false
OK.