<?php
set_time_limit(0);
if($_POST['login'])
{
$php_userid = rawurlencode($_POST['login']);
$php_password = rawurlencode($_POST['passwd']);
$cookie_file_path = “C:\wamp\www\curl\cookie.txt”; // Please set your Cookie File path
//$cookie_file_path = “/home/phptrack/public_html/curl/cookie.txt”; // Please set your Cookie File path
$fp = fopen($cookie_file_path,’wb’);
fclose($fp);
$agent = “Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7″;
$reffer = “https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%3Fnsr%3D1%26ui%3Dhtml%26zy%3Dl<mpl=default<mplcache=2&hl=en”;
//1. Get first login page to parse hash_u,hash_challenge
$LOGINURL = “http://mail.google.com/mail/?logout&hl=en”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
// 2- Post Login Data to Page https://login.hot.com/config/login?
$LOGINURL = “https://www.google.com/accounts/ServiceLoginAuth?service=mail”;
$POSTFIELDS = “ltmpl=default<mplcache=2&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F%3Fnsr%3D1&service=mail&rm=false<mpl=default&GALX=g6xwRHgzxWY&Email=”.$php_userid.”&Passwd=”.$php_password.”&rmShown=1&signIn=Sign+in”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
////echo $result;
curl_close ($ch);
//echo “<textarea rows=30 cols=130>”.$result.”</textarea>”;
$LOGINURL = “http://mail.google.com/mail”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
//echo “<textarea rows=30 cols=130>”.$result.”</textarea>”;
// parse http://mail.google.com/mail/?ui=2&ik=b7e8a936c2&view=cbj
//ID_KEY = ‘b7e8a936c2′,
$arr_post = ”;
preg_match_all(“/ID_KEY = ‘(.*?)\’/”, $result, $arr_post);
$url_login = $arr_post[1][0];
$id_key = $arr_post[1][0];
$url = ‘http://mail.google.com/mail/?ui=2&ik=’.$url_login.’&view=cbj’;
//print “\r\n<br> loading:”.$url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
curl_close ($ch);
//echo “<textarea rows=30 cols=130>”.$result.”</textarea>”;
$url = ‘http://mail.google.com/mail/?ui=2&ik=’.$id_key.’&view=tl&start=0&num=70&init=1&rt=h&search=inbox’;
//print “\r\n<br> loading:”.$url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
curl_close ($ch);
//echo “<textarea rows=30 cols=130>”.$result.”</textarea>”;
$arr_post = ”;
echo $result;
preg_match_all(“/email(.*?)\”(.*?)\\\/”, $result, $arr_post);
print ‘<PRE>’;
print_r($arr_post[2]);
print ‘</PRE>’;
} // extra code 2 if
else
{
login_form();
}
////////////////////////////////////////////////////////////////////////////////////////////////
function login_form()
{
?>
<html>
<head>
<title>g Mail</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>
<body>
Get gmail Email Address Contact List
<form method=”post” action=”gmail.php” autocomplete=off name=”login_form” >
<table id=”yreglgtb” summary=”form: login information”>
<tbody><tr>
<th><label for=”username”>gmail Email:</label></th>
<td><input name=”login” id=”login” value=”" size=”17″ class=”yreg_ipt” type=”text”></td>
</tr>
<tr>
<th><label for=”passwd”>Password:</label></th>
<td><input name=”passwd” id=”passwd” value=”" size=”17″ class=”yreg_ipt” type=”password”></td>
</tr>
</tbody></table>
<input value=”Sign In” type=”submit”>
</form>
</body>
</html>
<?php
}
?>