PHP Sina Pass login Sina Weibo login Demo login (browser version) 2016

Source: Internet
Author: User
Tags urlencode
Due to the need for project management microblogging platform content, integrated login microblogging management platform features, so in the crawl web based on the browser to explore the simulation login, has realized the login function, using jquery and PHP in a combination of ways, which need to pay attention to cross-domain access issues, the code is as follows:

  ' login.sina.com.cn ', ' user-agent ' = ' mozilla/5.0 ' (Windows NT 6.1; WOW64; rv:45.0) gecko/20100101 firefox/45.0 ', ' Accept ' = ' */* ', ' accept-language ' + ' zh-cn,zh;q=0.8,en-us;q=0.5,en;q= ' 0.3 ', ' accept-encoding ' = ' gzip, deflate ', ' Referer ' = ' http://login.sina.com.cn/', ' Connection ' and ' = ' Keep-alive ');//base64 encrypted username private $su = ";//js encrypted password private $sp ="; function __construct () {}//pre-login function Pre_login () {//User name Base64 encryption-for pre-Login $this->su = Base64_encode (UrlEncode ($this->username));//Pre-login Url$pre_login_url = ' http ://login.sina.com.cn/sso/prelogin.php?entry=account&callback=sinassocontroller.prelogincallback&su= '; $ Pre_login_url = $pre _login_url. $this->su. ' &rsakt=mod&client=ssologin.js (v1.4.15) &_= '. Time (); $return _val = $this->request_url ($pre _login_url, NULL, $this->request_cookie, $this->request_ Headers) List ($header, $body) = Explode ("\r\n\r\n", $return _val, 2);p Reg_match_all ("/set\-cookie: ([^;] *);/", $header, $matches); $info [' cookie '] = $matches; $info [' header '] = $header; $info [' content '] = $body; $this->request_cookie. = $mat Ches, $body = Str_replace (' Sinassocontroller.prelogincallback (', ', ', $body); $json = Str_replace (') ', ' ', $body); $this- >json_obj = Json_decode ($json);//ajax after variable reset, so save to Cookieparam::set_cookie (' Sina_su ', $this->su);p aram::set_ Cookies (' Sina_cookie ', $this->request_cookie);p aram::set_cookie (' Sina_servertime ', $this->json_obj-> Servertime);p Aram::set_cookie (' sina_nonce ', $this->json_obj->nonce);p aram::set_cookie (' sina_rsakv ', $this- >JSON_OBJ->RSAKV);//Encrypt plaintext password $this->ajax_pwd_encode ();} Login function Account_login () {//Login Url$login_url = ' http://login.sina.com.cn/sso/login.php?client= based on pre-login return information Ssologin.js (v1.4.15) &_= '. Time (); $this->request_headers[' content-type '] = ' application/ X-www-form-urlencoded ';//login Required Data $post_data[' entry ' = ' account ', $post _data[' gateway '] = ' 1 '; $post _data[' from '] = '; post_data[' savestate '] = ' 0 '; $post _data[' useticket ') = ' 0 '; $post _data[' pagerefer ') = '; $post _data[' vsnf '] = ' 1 '; $post _data[' su '] = Param::get_cookie (' Sina_su '); $post _data [' service '] = ' sso '; $post _data[' servertime '] = Param::get_cookie (' sina_servertime '); $post _data[' nonce '] = Param::get _cookie (' sina_nonce '); $post _data[' pwencode '] = ' rsa2 '; $post _data[' rsakv '] = Param::get_cookie (' sina_rsakv '); $post _ data[' sp '] = $this->sp; $post _data[' sr '] = ' 1366*768 '; $post _data[' encoding '] = ' UTF-8 '; $post _data[' cdult '] = ' 3 '; $ post_data[' domain ' = ' sina.com.cn '; $post _data[' prelt '] = ' Wuyi '; $post _data[' returntype '] = ' TEXT ';//Login $data = $this- >request_url ($login _url, $post _data, $this->request_cookie, $this->request_headers);//Get a return cookie and JSON data list ($header, $body) = Explode ("\r\n\r\n", $data, 2);//Save Cookie$this->save_cookie ($header); $json _login = js On_decode ($body);//Access return JSON link $domain_urls = $json _login->crossdomainurllist; $i = 0;foreach ($domain _urls as $v) {$ Req_url = $v. ' &callback=sinassocontroller.docrossdomaincallback&scrIptid=ssoscript '. $i. ' &client=ssologin.js (v1.4.15) &_= '. Time (); $req _data = $this->request_url ($req _url, NULL, $this->request_cookie, Array ()), List ($header, $body) = Explode ("\r\n\r\n", $data, 2); $this->save_cookie ( $header); $i + +;}} function Save_cookie ($header) {$headers = explode (' \ r \ n ', $header), foreach ($headers as $v) {$tmp = explode ("\ r \ n", $v); fo Reach ($tmp as $it) {$pos = Strpos ($it, ' Set-cookie '), if ($pos!== false) {$CV = Explode (":", $it); $this->request_cooki E. = $CV [1]. '; '; $_cookie[$CV [0]] = $CV [1];setcookie ($CV [0], $CV [1], Time () +60*60*24*30);p Aram::set_cookie ($CV [0], $CV [1]);}}} Login function Browser_login () {//Login Url$login_url = ' http://login.sina.com.cn/sso/login.php?client= based on pre-login return information Ssologin.js (v1.4.15) &_= '. Time ();//login Required Data $post_data[' entry '] = ' account '; $post _data[' gateway '] = ' 1 '; $post _data [' from '] = '; $post _data[' savestate '] = ' 0 '; $post _data[' useticket '] = ' 0 '; $post _data[' pagerefer '] = '; $post _data[' VSNF '] = ' 1 '; $post _data[' su '] = param::Get_cookie (' Sina_su '); $post _data[' service '] = ' sso '; $post _data[' servertime '] = Param::get_cookie (' Sina_servertime ') ); $post _data[' nonce '] = Param::get_cookie (' sina_nonce '); $post _data[' pwencode '] = ' rsa2 '; $post _data[' rsakv '] = param: : Get_cookie (' sina_rsakv '); $post _data[' sp '] = $this->sp; $post _data[' sr '] = ' 1366*768 '; $post _data[' encoding '] = ' UTF-8 '; $post _data[' cdult '] = ' 3 '; $post _data[' domain '] = ' sina.com.cn '; $post _data[' prelt '] = ' Wuyi '; $post _data[' ReturnType '] = ' TEXT '; Echo '"; Echo""; Echo"
 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  "; echo" "; echo""; Echo"";} function Sina_login () {//get encrypted password $THIS-&GT;SP = $_get[' SP '];//account login $this->browser_login ();} Invoke JS cryptographic password function Ajax_pwd_encode () {echo ""; Echo <<
  
   $v) {$o. = "$k =". UrlEncode ($v). "&";} $post _data = substr ($o, 0,-1); $is _post = true;} $ch = Curl_init (); Initialize Curlcurl_setopt ($ch, Curlopt_url, $url); Crawl specified Web page curl_setopt ($ch, Curlopt_returntransfer, 1); The result is a string and output to the on-screen if ($is _post) {curl_setopt ($ch, Curlopt_post, 1);//Post Submission Method curl_setopt ($ch, Curlopt_postfields, $ Post_data); Post Data} curl_setopt ($ch, Curlopt_cookie, $request _cookies); Request Cookiecurl_setopt ($ch, Curlopt_header, $return _cookie); Returns the cookie to the head curl_setopt ($ch, Curlopt_connecttimeout, curl_setopt); ($ch, Curlopt_httpheader, $request _headers); c Url_setopt ($ch, curlopt_followlocation, 1); $data = Curl_exec ($ch); Run Curlcurl_close ($ch); return $data;}}? >
  
 
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.