Automate login pages using PHP-cURL

Discussion in 'PHP' started by reinaldo83, Mar 27, 2008.

  1. #1
    Hi.

    I hope you can help me with this.

    I'm trying to login a site using PHP-cURL and i have this code:

    
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, 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($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_COOKIEFILE, "cookiefile.txt");
    curl_setopt($curl, CURLOPT_COOKIEJAR, "cookiefile.txt");
    curl_setopt($curl, CURLOPT_URL, "http://www.anydomain.com/login.php");
    curl_setopt($curl, CURLOPT_POSTFIELDS, "un=username&pw=password&");
    
    $login = curl_exec ($curl);
    
    curl_close ($curl);
    
    echo $login;
    
    
    Code (markup):
    I think this code works because after i execute this script i can see the cookiefile.txt and it contains the session id information. So, technically i've logged in the site.

    The problem is i'd like to get the source code of some pages or to see some pages after the login, but i don't know what do i need to add to the code.

    I've put fopen function after and before the curl_exec, i've set up a new CURLOPT_URL function puting the complete URL (because it allows GET method) and even i've write this:

    
    curl_setopt($curl, CURLOPT_URL, "https://www.anydomain.com/page2.php");
    $inside = curl_exec ();
    curl_close ($curl);
    echo $inside;
    
    Code (markup):
    I think adding and executing this too, i should see https://www.anydomain.com/page2.php directly in my browser, right???

    Can you help me with this saying to me how to see or how to get the source code of an HTTPS inside the login form?

    Thank in advance!

    Rgds.

    Reinaldo.

    P.D.: Sorry for my english, i know it isn't very good.
     
    reinaldo83, Mar 27, 2008 IP