1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

yahoo curl login :stuck

Discussion in 'PHP & Perl' started by maximviper, Feb 12, 2011.

  1. maximviper

    maximviper BANNED BANNED

    Joined:
    Oct 25, 2010
    Messages:
    338
    Likes Received:
    86
    i made the code below . but still i cant make it work. the problem is yahoo is implementing a captcha challange for this kind of automated headers. do you have any idea ho to make it work again without alerting the captcha challange ?

    PHP:
    <?php

        
        $authUrl    
    "https: //login.  yahoo  .   com/config/login?";
        
    $userAgent  "Mozilla/5.0 (Windows NT 5.1; rv:2.0b11) Gecko/20100101 Firefox/4.0b11";
        
    $referer    "http  :  //  my  .  yahoo  .  com";
        
    $login      "userid";
        
    $password   "password";
        
    $numPostData 22;
        
    $cookieFileJar  "ycookie.txt";
        
    $cookie 0;
        
    $postData ".tries=1&.src=ym&.md5=&.hash=&.js=&.last=&promo=&.intl=in&.bypass=&.partner=&.u=4ls6cr96lbs8e&.v=0&.challenge=W9w31pCrbdazCcY4mH41fVsyxwd8&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=0&.chkP=Y&.done=http%3A%2F%2Fmail.yahoo.com&.pd=ym_ver%3D0%26c%3D%26ivt%3D%26sg%3D&pad=1&aad=1&login=$login&passwd=$password&.persistent=y&.save=&passwd_raw=" ;

        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_USERAGENT$userAgent);

        
    // Set the referrer
        
    curl_setopt($chCURLOPT_REFERER$referer);

        
    // Set the authentication url
        
    curl_setopt($chCURLOPT_URL$authUrl);

        
    // Set number of post fields
        
    curl_setopt($chCURLOPT_POST$numPostData);

        
    //Set post data in key=value pair such as login=yourusername
        
    curl_setopt($chCURLOPT_POSTFIELDSTRUE);

        
    //Set filename for storing cookie information
        
    curl_setopt($chCURLOPT_COOKIEJAR$cookieFileJar);

        
    //Set ffilename for checking the stored cookie information
        
    curl_setopt($chCURLOPT_COOKIEFILE$cookieFileJar);

        
    //Set option for cookie
     //   curl_setopt($ch, CURLOPT_COOKIE, $cookie);
     
     //set this to output the result as string and not output directly ot browser
        
    curl_setopt($chCURLOPT_RETURNTRANSFERTRUE);

     
    //set this value to 1 if you want to redirect to the url you provided as service url
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION0);
     
     
    //Set this option if you do not want to verify ssl
        
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
     
     
    //set this option if you do not want to verify peer's certificate
        
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
     
     
    //now execute the curl
        
    $res curl_exec($ch);
         echo 
    $res;
     
    //check if the username and password is valid
        
    if ((preg_match("/invalid/i"$res)) || (preg_match("/not yet taken/i"$res))) {
            echo 
    "Invalid Login";
        }
        else {
      
    //if  CURLOPT_FOLLOWLOCATION is set to 1 then after logging in successfully user is directed to url that is specified as service url
            
    echo "Logged In";
        }
    ?>
     
  2. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,927
    Likes Received:
    1,944
    Home Page:
    Works fine for me, make sure to scrape the hidden values on the first page & set a session cookie rather than just straight up posting the data through though:
    PHP:
    <?php
    $curl_defaults 
    = array(
        
    CURLOPT_RETURNTRANSFER => true
        
    CURLOPT_HEADER => 0,
        
    CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 5.1; rv:2.0b11) Gecko/20100101 Firefox/4.0b11',
        
    CURLOPT_FOLLOWLOCATION => 1,
        
    CURLOPT_AUTOREFERER => 1,
        
    CURLOPT_RETURNTRANSFER => 1,
        
    CURLOPT_CONNECTTIMEOUT => 5,
        
    CURLOPT_TIMEOUT => 20,
        
    CURLOPT_VERBOSE => 0,
        
    CURLOPT_SSL_VERIFYHOST => 0,
        
    CURLOPT_SSL_VERIFYPEER => 0
        
    );
    function 
    Return_Content_From_URL($url,$cookies){
        global 
    $curl_defaults;
        
    $ch curl_init();
        
    curl_setopt_array($ch$curl_defaults);
        
    curl_setopt($chCURLOPT_URL,$url);
        
    curl_setopt($chCURLOPT_COOKIEJAR$cookies.'.txt');
        
    curl_setopt($chCURLOPT_COOKIEFILE$cookies.'.txt');
        
    $htmlcurl_exec($ch);
        
    curl_close($ch);
        return 
    $html;
        }
    function 
    Post_And_Return($url,$cookies,$data,$referrer){
        global 
    $curl_defaults;
        
    $ch curl_init();
        
    curl_setopt_array($ch$curl_defaults);
        
    curl_setopt($chCURLOPT_URL,$url);
        
    curl_setopt($chCURLOPT_REFERER$referrer);
        
    curl_setopt($chCURLOPT_POSTFIELDS,$data);
        
    curl_setopt($chCURLOPT_COOKIEJAR$cookies.'.txt');
        
    curl_setopt($chCURLOPT_COOKIEFILE$cookies.'.txt');
        
    $html curl_exec($ch);
        
    curl_close($ch);
        return 
    $html;
        }
    function 
    getHiddenFields($html){
        
    $ret = array();
        if (
    preg_match_all('#(<input[^>]*type="hidden"[^>]*>)#is'$html$matches)){
            
    $hfields $matches[1];
            foreach (
    $hfields as $hf) {
                if (
    preg_match('#name="([^"]+)"#is'$hf$matches)){
                    
    $hf_name $matches[1];
                    
    $hf_val '';
                    if (
    preg_match('#value="([^"]+)"#is'$hf$matches)){
                        
    $hf_val $matches[1];
                        }
                    
    $ret[] = urlencode(htmlspecialchars_decode($hf_name)).'='.urlencode(htmlspecialchars_decode($hf_val));
                    }
                }
            }
        return 
    $ret;
        }
    // Set Cookies File
    $cookies "yahoo";
    // Set Account Details
    $email "[email protected]";
    $password "password";
    // Return Content From Login Page
    $url "https://login.yahoo.com/config/login?";
    $content Return_Content_From_URL($url,$cookies);
    // Scrape Form Values
    $fields getHiddenFields($content);
    // Join Hidden Fields
    $data join('&'$fields);
    // Form Post Data
    $data.="&login=".$email;
    $data.="&passwd=".$password;
    // Post Login Info
    $url "https://login.yahoo.com/config/login?";
    $referrer "http://my.yahoo.com/";
    $content Post_And_Return($url,$cookies,$data,$referrer);
    // Go To My Yahoo
    $url "http://mail.yahoo.com/";
    $content Return_Content_From_URL($url,$cookies);
    echo 
    "<textarea>".htmlentities($content)."</textarea>";
    ?>
     
    • Thanks Thanks x 1
  3. maximviper

    maximviper BANNED BANNED

    Joined:
    Oct 25, 2010
    Messages:
    338
    Likes Received:
    86
    yhankyou very much sir. i will try it right away :)
     
  4. Crazy

    Crazy Jr. Executive VIP

    Joined:
    Jun 13, 2009
    Messages:
    640
    Likes Received:
    319
    Occupation:
    VB, C#, XHTML, CSS, PHP, MySQL, JavaScript, jQuery
    Location:
    Everywhere
    gimme4free is correct, Yahoo much like everything else (Facebook, AOL, MySpace) are multi-step login procedures where unique content is required for subsequent steps. So don't overlook parsing important tokens throughout everything you need done. Feel free to PM me anytime if you need help with shit like this.
     
  5. chronic

    chronic Newbie

    Joined:
    Aug 15, 2008
    Messages:
    38
    Likes Received:
    27
    Crazy.

    Regards to your PM, I cannot reply to you as I don't have 15 posts yet so if you want you can add me GTalk at finney.cc