<?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($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies.'.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies.'.txt');
$html= curl_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($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_REFERER, $referrer);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies.'.txt');
curl_setopt($ch, CURLOPT_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>";
?>