A few days ago, I first tested how to use Python scripts to log on to Baidu space. The problem has been solved. I can refer to my blog post "logging on to Baidu space using python scripts". Today I have improved the php login process, the logon principle is the same as that of the python script. The Code is as follows: logon code privatefunctionloginBaiduZone ($ user, $ password) {getCookie $ ret
A few days ago, I first tested how to use Python scripts to log on to Baidu space. The problem has been solved. I can refer to my blog post "logging on to Baidu space using python scripts". Today I have improved the php login process, the logon principle is the same as that of the python script. The Code is as follows: the logon code private function loginBaiduZone ($ user, $ password) {// get Cookie $ ret
A few days ago, I first tested how to use Python scripts to log on to Baidu space. The problem has been solved. I can refer to my blog post "logging on to Baidu space using python scripts". Today I have improved the php login process, the logon principle is the same as that of the python script.
The Code is as follows:
Logon code
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");}
Tool functions for Http requests
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;}
Next, test the post code.
The post PHP is used to log on to The Baidu space appeared first on without any problems.