使用 curl() 函數實現不同網站之間註冊使用者的同步

來源:互聯網
上載者:User

標籤:ror   errno   返回   網站   16px   cookies   use   pos   err   

一 需求

在A網站註冊一個新使用者,那麼,在B網站也會被同時註冊

二 思路

在A網站註冊的同時,調用API介面實現在B網站也會被同時註冊

三 實現

主要代碼如下:

 1 function http_curl($url,$post=‘‘,$cookie=‘‘, $returnCookie=0){ 2     $curl = curl_init(); 3     curl_setopt($curl, CURLOPT_URL, $url); 4     curl_setopt($curl, CURLOPT_USERAGENT, ‘Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)‘); 5     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 6     curl_setopt($curl, CURLOPT_AUTOREFERER, 1); 7     curl_setopt($curl, CURLOPT_REFERER, "http://XXX"); 8     if($post) { 9         curl_setopt($curl, CURLOPT_POST, 1);10         curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));11     }12     if($cookie) {13         curl_setopt($curl, CURLOPT_COOKIE, $cookie);14     }15     curl_setopt($curl, CURLOPT_HEADER, $returnCookie);16     curl_setopt($curl, CURLOPT_TIMEOUT, 10);17     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);18     $data = curl_exec($curl);19     if (curl_errno($curl)) {20         return curl_error($curl);21     }22     curl_close($curl);23     if($returnCookie){24         list($header, $body) = explode("\r\n\r\n", $data, 2);25         preg_match_all("/Set\-Cookie:([^;]*);/", $header, $matches);26         $info[‘cookie‘]  = substr($matches[1][0], 1);27         $info[‘content‘] = $body;28         return $info;29     }else{30         return $data;31     }32 }
View Code

參數說明:參數1為訪問的URL,參數2為post資料(不填則為GET),參數3為提交的$cookies,參數4為是否返回$cookies。

使用 curl() 函數實現不同網站之間註冊使用者的同步

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.