Heim > php教程 > php手册 > Hauptteil

PHP 登录百度空间

WBOY
Freigeben: 2016-06-06 20:09:29
Original
1416 Leute haben es durchsucht

前几天,先测试了利用Python脚本登录百度空间,问题已解决,可以参照我的博文《python 脚本登录百度空间》,今天完善了php方式的登录过程,原理同python脚本的登录。 代码如下: 登录代码 private function loginBaiduZone($user,$password){//get Cookie$ret

前几天,先测试了利用Python脚本登录百度空间,问题已解决,可以参照我的博文《python 脚本登录百度空间》,今天完善了php方式的登录过程,原理同python脚本的登录。

代码如下:

登录代码

private function loginBaiduZone($user,$password)
{
//get Cookie
$ret = $this->doHttpPost("https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=false", "", "");
//get token
$ret = $this->doHttpPost("https://passport.baidu.com/v2/api/?getapi&class=login&tpl=mn&tangram=false", "", "");
preg_match_all('/login_token=\'(.+)\'/', $ret, $tokens);
$login_token = $tokens[1][0];
//login
$post_data = array();
$post_data['username'] = $user;
$post_data['password'] = $password;
$post_data['token'] = $login_token;
$post_data['charset'] = "UTF-8";
$post_data['callback'] = "parent.bd12Pass.api.login._postCallback";
$post_data['index'] = "0";
$post_data['isPhone'] = "false";
$post_data['mem_pass'] = "on";
$post_data['loginType'] = "1";
$post_data['safeflg'] = "0";
$post_data['staticpage'] = "https://passport.baidu.com/v2Jump.html";
$post_data['tpl'] = "mn";
$post_data['u'] = "http://www.baidu.com/";
$post_data['verifycode'] = "";
$ret = $this->doHttpPost("http://passport.baidu.com/v2/api/?login", $post_data, "https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F");
}
Nach dem Login kopieren

Http请求的工具函数

private function doHttpPost($url, $post_data, $referef)
{
$mcurl = curl_init();
curl_setopt($mcurl, CURLOPT_URL, $url);
if ($post_data != "")
{
curl_setopt($mcurl, CURLOPT_POST, 1);
curl_setopt($mcurl, CURLOPT_POSTFIELDS, $post_data);
}
if ($referef != "")
{
curl_setopt($mcurl, CURLOPT_REFERER, $referef);
}
curl_setopt($mcurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($mcurl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($mcurl, CURLOPT_HEADER, 1);
curl_setopt($mcurl,????CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.92 Safari/537.1 LBBROWSER");
if ($this->cookie != "")
{
curl_setopt($mcurl, CURLOPT_COOKIE, $this->cookie);
}
$data = curl_exec($mcurl);
curl_close($mcurl);
preg_match_all('/Set-Cookie:((.+)=(.+))$/m ', $data, $cookies);
if(is_array($cookies) && count($cookies) > 1 && count($cookies[1]) > 0)
{
foreach($cookies[1] as $i => $k)
{
$cookieinfos = explode(";", $k);
if(is_array($cookieinfos) && count($cookieinfos) > 1)
{
$this->cookie .= $cookieinfos[0];
$this->cookie .= "; ";
}
}
}
return $data;
}
Nach dem Login kopieren

接下来再测试博文的发布代码。

The post PHP 登录百度空间 appeared first on 润物无声.

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!