Jump to content

curl login to Yahoo webmail


jozard

Recommended Posts

hi
I'm trying to create a program that automatically logs in to Yahoo/AOL webmail (with my user and password).

I analyzed all they're hidden fields and all, and still something does not seem to work!!
if anyone here could help me i'd be greatful!

[sup]
function HiddenFields($contents)
{

        preg_match('/name="login_form">[\s\S]*yreglgtb/',$contents,$matches);
        $str= implode(';',$matches);
        $matches2= explode ('<',$str);

        //------------ creating $params (all hidden fields) ------------
        $names='';
        $n=1;
        while ($n+1 < count($matches2))
        {
                $str1=$matches2[$n];
                preg_match('/name="[\s\S]*" value/',$str1,$match);
                $value = str_replace('name="','',$match[0]);
                $value = str_replace('" value','',$value);
                $names.=$value.';';
                $n++;
        }
        $names = explode (';',$names);

        $values='';
        $n=1;
        while ($n+1 < count($matches2))
        {
                $str1=$matches2[$n];
                preg_match('/value="[\s\S]*">/',$str1,$match);
                $value = str_replace('value="','',$match[0]);
                $value = str_replace('">','',$value);
                $values.=$value.';';
                $n++;
        }
        $values = explode (';',$values);

        $params='';
        $n=0;
        while ($n+1 < count($names))
        {
                $params.=$names[$n].'='.$values[$n].'&';
                $n++;
        }
     
        return $params;
     
} //HiddenFields [/sup]

this function takes all the hidden fields in the specific login form and returns it into $params as $params='name=value&name2=value2....'

[sup]
$varURL1 = 'https://login.yahoo.com/config/mail';

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
//curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_URL,$varURL1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
//curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $params);

$contents=curl_exec($ch);
curl_close($ch);
$params = HiddenFields($contents);

$params.= 'login='.$username;
$params.= '&passwd='.$password;
$params.= '&.save=Sign In';


$varURL2='https://login.yahoo.com/config/login?';
$varURL2='https://login.yahoo.com/config/login?';

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_REFERER, $varURL1 );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_URL,$varURL2);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);

echo $content=curl_exec($ch);

curl_close($ch); ?>[/sup]

thanks!
Link to comment
https://forums.phpfreaks.com/topic/35111-curl-login-to-yahoo-webmail/
Share on other sites

  • 1 year later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.