Automatic login script

Discussion in 'PHP' started by nashah, May 18, 2010.

  1. #1
    This script is to automated our log-in to some site.
    You must have cURL installed to use this script.
    When I started to code this script , at that time I was having some difficulties to code and finally I got the success to programmed auto log-in script. From internet I have research allot to create such a script , but there is no correct solution available for this script on internet . This script is really help you to logging in to different site automatically when you run it .

    // INIT CURL
    $ch = curl_init();

    // SET URL FOR THE POST FORM LOGIN
    curl_setopt($ch, CURLOPT_URL, 'http://www.external-site.com/Members/Login.php');

    //Reference URL that where you going to login
    curl_setopt($ch, CURLOPT_REFERER, "RefUrl");

    // ENABLE HTTP POST
    curl_setopt ($ch, CURLOPT_POST, 1);

    // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
    curl_setopt ($ch, CURLOPT_POSTFIELDS, 'fieldname1=fieldvalue1&fieldname2=fieldvalue2,...');

    //Cookie file
    curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie.txt');

    // IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
    curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

    //set session cookie
    curl_setopt ($ch, CURLOPT_COOKIE, 'cookie.txt');

    //Usage of CURLOPT_FOLLOWLOCATION is important when sites use URL redirectors for //file downloads
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);


    // Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
    // not to print out the results of its query.
    //Instead, it will return the results as a string return value
    // from curl_exec() instead of the usual true/false.
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

    // EXECUTE 1st REQUEST (FORM LOGIN)
    $result = curl_exec($ch);

    // CLOSE CURL
    curl_close ($ch);


    Thanks,
    Regards
    Nasir ALi Shah
     
    Last edited: May 18, 2010
    nashah, May 18, 2010 IP
  2. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #2
    Hmmmm...
    Just you copied and pasted for Underground training world!
    Also where is the the username and pass section declaration or field?
     
    roopajyothi, May 18, 2010 IP