PHP Help Needed: Yahoo Login Using cURL

skywalker55

New member
Feb 4, 2012
2
0
0
Im building a web application for a client at the moment and I have succesfully automated the process for aol. So the basic cURL operation works...but im really struggling with yahoo. I just cannot get the login to correctly authenticate. Any help / advice would be really appreciated.

The code is below..Its failing at the login step where its causing capchers tto be shown, despite the correct username/password.

PHP:
    function cron_submit_yahoo_fbl($domain, $proxies, $maxProxyArray)
    {    
        //temporarily set the yahoo login details..
        $username = 'myusername';
        $password = 'mypassword';
    
        //initiate cUrl
        $ch = $this->curlinit();

        //login to yahoo..
        echo "logging in<br/>";
        $s = $this->curlget($ch,'http://feedbackloop.yahoo.net/index.php','http://feedbackloop.yahoo.net/index.php');
        $packet = "action=loginUser&openid_url=yahoo.com&Submit.x=90&Submit.y=20";
        $s = $this->curlpost($ch, 'http://feedbackloop.yahoo.net/index.php','http://feedbackloop.yahoo.net/index.php',$packet);
        $u = $this->svalue($s,'&.u=','&partner=');
        echo 'u is'.$u.'<br/>';
        $challenge = $this->svalue($s,'<input type="hidden" name=".challenge" value="','">');
        echo 'challenge is'.$challenge.'<br/>';
        $pd = $this->svalue($s,'<input type="hidden" name=".pd" value="','">');
        echo 'pd is'.$pd.'<br/>';
        $done = $this->svalue($s,'<input type="hidden" name=".done" value="','">');

        $ref = 'https://login.yahoo.com/config/login?.intl=us&.src=openid&.partner=&.pd='.urlencode($pd).'&.done='.urlencode($done);
        $postUrl = 'https://login.yahoo.com/config/login';
        $login_packet ='.tries=1&.src=openid&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.lang=en-US&.bypass=&.partner=&.u='.$u.'&.v=0&.challenge='.$challenge.'&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done='.urlencode($done).'&.pd='.urlencode($pd).'&.ws=1&.cp=0&pad=16&aad=16&login='.$username.'&passwd='.$password.'&.persistent=on&.save=Sign%20In&passwd_raw=';    

        $s = $this->curlpost($ch,$postUrl,$ref,$login_packet);

        //THE CODE FAILS AT THIS POINT...WHEN I echo $s im getting an indication that yahoo is presenting capcher but I cant get access to it..
        echo $s;
        
        $rd = $this->svalue($s,'<meta http-equiv="Refresh" content="0; url=','">');
        echo 'rd is'.$rd.'<br/>';
     
        if ($rd) 
        {
            echo "logged in<br/>";          
            $s = $this->curlget($ch,$rd,'https://login.yahoo.com/config/login?');
            $val['s']=$s;
            $val['ch'] = $ch;
            echo "got fbl redirect and tasty cookies<br/>";
            //return($val);
        } 
        else 
        {
            echo  "error logging in. check username/password<br/>";
            exit;
        }        


        //close the curl connection.. 
        curl_close($ch);
    
    }


PHP:
    function curlinit()
    {        
        $upload_dir = 'uploads/';
        $config['upload_path'] = realpath($upload_dir);
        $cookieJarFile = $config['upload_path'].'/cookie.txt';
        
        $ch = curl_init();
        $curl_opts = array( 
                CURLOPT_SSL_VERIFYHOST=> 0, 
                CURLOPT_SSL_VERIFYPEER=> 0, 
                CURLOPT_HEADER=> 1,
                CURLOPT_VERBOSE=> 1,
                CURLOPT_FOLLOWLOCATION=> 1, 
                CURLOPT_AUTOREFERER=> 0, 
                CURLOPT_RETURNTRANSFER=> 1, 
                CURLOPT_TIMEOUT=> 20, 
                CURLOPT_CONNECTTIMEOUT=> 15, 
                CURLOPT_COOKIEFILE=> $cookieJarFile, 
                CURLOPT_COOKIEJAR=> $cookieJarFile, 
                CURLOPT_COOKIESESSION=> 1, 
                CURLOPT_DNS_USE_GLOBAL_CACHE=> 0, 
                CURLOPT_USERAGENT=> 'Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.0.13) Gecko/2009073022');
        curl_setopt_array($ch,$curl_opts);                
        return($ch);
    }    
    
    function curlpost($ch,$url,$ref,$packet)
    {
        curl_setopt($ch,CURLOPT_POST,1);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$packet);
        curl_setopt($ch,CURLOPT_URL,$url);        
        if ($ref) { curl_setopt($ch,CURLOPT_REFERER,$ref); }
        curl_setopt($ch,CURLOPT_HTTPHEADER, array("Keep-Alive: 115", "Connection: keep-alive", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: en-us,en;q=0.5","Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7","User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.0.13) Gecko/2009073022"));
        $s=curl_exec($ch);
        return($s);
    }
    
    function svalue($source,$tag1,$tag2)
    {
        $source=str_replace($tag1,"<tagged>",$source);
        $source=str_replace($tag2,"</tagged>",$source);
        preg_match('#<tagged>(.*)</tagged>#',$source,$result);
        $string = $result[1];
        $string=str_replace("<tagged>",null,$string);
        $string=str_replace("</tagged>",null,$string);        
        return($string);
    }    
    
    function curlget($ch,$url,$ref)
    {
        curl_setopt($ch,CURLOPT_POST,0);
        curl_setopt($ch,CURLOPT_URL,$url);
        if (strlen($ref) > 1 ) { curl_setopt($ch,CURLOPT_REFERER,$ref); }
        curl_setopt($ch,CURLOPT_ENCODING, 'gzip,deflate');
        curl_setopt($ch,CURLOPT_HTTPHEADER, array("Keep-Alive: 115", "Connection: keep-alive", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: en-us,en;q=0.5","Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7","User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.0.13) Gecko/2009073022"));
        $s=curl_exec($ch);
        return($s);
    }