[help] auto login using curl

Discussion in 'PHP' started by ankit_frenz, Mar 25, 2009.

  1. #1
    i have not worked much with curl...can someone tell me why this auto login script is not working:-

    
    <?php
    error_reporting (E_ALL | E_STRICT);
    set_time_limit(0);
    
    
    function curl_login($url,$data,$proxy,$proxystatus){
        $fp = fopen("cookie.txt", "w");
        fclose($fp);
        $login = curl_init();
        curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
        curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
        curl_setopt($login, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
        curl_setopt($login, CURLOPT_TIMEOUT, 40);
        curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
        if ($proxystatus == 'on') {
            curl_setopt($login, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($login, CURLOPT_HTTPPROXYTUNNEL, TRUE);
            curl_setopt($login, CURLOPT_PROXY, $proxy);
        }
        curl_setopt($login, CURLOPT_URL, $url);
        curl_setopt($login, CURLOPT_HEADER, TRUE);
        curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($login, CURLOPT_POST, TRUE);
        curl_setopt($login, CURLOPT_POSTFIELDS, $data);
        ob_start();      // prevent any output
        return curl_exec ($login); // execute the curl command
        ob_end_clean();  // stop preventing output
        curl_close ($login);
        unset($login);    
    }                   
    
    function curl_grab_page($site,$proxy,$proxystatus){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        if ($proxystatus == 'on') {
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
            curl_setopt($ch, CURLOPT_PROXY, $proxy);
        }
        curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
        curl_setopt($ch, CURLOPT_URL, $site);
        ob_start();      // prevent any output
        return curl_exec ($ch); // execute the curl command
        ob_end_clean();  // stop preventing output
        curl_close ($ch);
    } 
    
    curl_login('
    http://www.profilepic.com/','getusername=ankit_frenz&getpassword=testistest','','off');
    echo curl_grab_page('http://www.profilepic.com/page/account','','off');
    ?> 
    
    Code (markup):
    thx
     
    ankit_frenz, Mar 25, 2009 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    everything is correct except you need to print result of curl_exec of function curl_login
     
    javaongsan, Mar 25, 2009 IP
  3. ankit_frenz

    ankit_frenz Active Member

    Messages:
    1,111
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    63
    #3
    but i donot want to echo the result...i just want to grab the profile page after being logged in..
    still i tried to modify the code as suggested by you...but no success :(
    
    echo curl_login('
    http://www.profilepic.com/','getusername=ankit_frenz&getpassword=testistest','','off');
    
    Code (markup):
     
    ankit_frenz, Mar 25, 2009 IP
  4. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #4
    I guess this site does allow auto login
     
    javaongsan, Mar 26, 2009 IP