Problems with PHP Impersonation login

Source: Internet
Author: User
Problems with PHP Impersonation login
On the Internet to read a series of articles to simulate Renren login, exactly now need to use, but appeared "the URL has moved here" is what reason AH. 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[' origurl '] = ' http://www.renren.com/indexcon ';    $post _fields[' domain '] = ' renren.com ';    The cookie file is stored under the Temp folder in the root directory of the Web site $cookie _file = Tempnam ('./temp ', ' Cookie ');    $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, Curlopt_maxredirs, 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);    Bring a 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);    Clean cookie file unlink ($cookie _file); Output Renren Home page content Print_r ($contents);


------Solution--------------------
The following content is posted.

This two-day simulation browser submits the login form, after submission is complete, the URL has movedhere.

Each time you need to click Connect to open the Login home page. That's not what I want.

Read again the description, see parameter-L

As follows:-l/--location follow location:hints (H)
--location-trusted follow Location:and send auth to other hosts (H)

A little impulsive, feeling 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

Wowowo Login after the homepage download down!!



Take a closer look at the D_COOKIE01 (containing content from C_COOKIE01, but the more concise--cookie-jar produced) there is such a

location:http://www.renren.com/callback.do?t=9d5201d04d44156fb070037e9493f5fd3&origurl=http%3a%2f% 2fwww.renren.com%2fhome.do&neednotify=false

The original after each submission of login form also need to jump, and-L is to follow the jump link.



We can also do it in two steps:

1. Submit the form first to 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 the 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, you get the home page after you sign in.
  • 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.