21,887
社区成员
发帖
与我相关
我的任务
分享
set_time_limit(0);
//cookie保存文件
$cookie_jar = tempnam('./tmp', 'cookie');
//登录的账号和密码
$post_fields['Email'] = '*************';
$post_fields['Passwd'] = '*******';
//模拟登录
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://www.google.com/accounts/ServiceLogin');
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar); //保存cookie
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$d = curl_exec($curl);
curl_close($curl);
//输出登录后的页面
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/accounts/ManageAccount');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar); //读取cookie
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
//输出页面
print $data;
<?php
set_time_limit(0);
//登录的账号和密码
$login = '*********';
$password = '*****';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://mail.google.com/mail/");
curl_setopt($ch, CURLOPT_REFERER, "");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');
//curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'read_header'));
$html = curl_exec($ch);
$matches = array();
$actionarr = array();
$action = "https://www.google.com/accounts/ServiceLoginAuth";
#parse the login form:
#parse all the hidden elements of the form
preg_match_all('/<input type\="hidden" name\="([^"]+)".*?value\="([^"]*)"[^>]*>/si', $html, $matches);
$values = $matches[2];
$params = "";
$i=0;
foreach ($matches[1] as $name)
{
$params .= "$name=" . urlencode($values[$i]) . "&";
++$i;
}
$login = urlencode($login);
$password = urlencode($password);
curl_setopt($ch, CURLOPT_URL, $action);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params ."Email=$login&Passwd=$password&PersistentCookie=");
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
$html = curl_exec($ch);
//输出登录后的页面
print $html;