A demand
Registering a new user at Site A, the B site will also be registered at the same time
Two ideas
At the same time as a site registration, call API interface implementation at the B site will also be registered
Three implementations
The main code is as follows:
1 functionHttp_curl ($url,$post= ",$cookie= ",$returnCookie=0){2 $curl=curl_init ();3curl_setopt ($curl, Curlopt_url,$url);4curl_setopt ($curl, Curlopt_useragent, ' mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; trident/6.0) ');5curl_setopt ($curl, Curlopt_followlocation, 1);6curl_setopt ($curl, Curlopt_autoreferer, 1);7curl_setopt ($curl, Curlopt_referer, "Http://XXX");8 if($post) {9curl_setopt ($curl, Curlopt_post, 1);Tencurl_setopt ($curl, Curlopt_postfields,Http_build_query($post)); One } A if($cookie) { -curl_setopt ($curl, Curlopt_cookie,$cookie); - } thecurl_setopt ($curl, Curlopt_header,$returnCookie); -curl_setopt ($curl, Curlopt_timeout, 10); -curl_setopt ($curl, Curlopt_returntransfer, 1); - $data= Curl_exec ($curl); + if(Curl_errno ($curl)) { - returnCurl_error ($curl); + } ACurl_close ($curl); at if($returnCookie){ - List($header,$body) =Explode("\r\n\r\n",$data, 2); - Preg_match_all("/set\-cookie: ([^;] *);/",$header,$matches); - $info[' cookie '] =substr($matches[1] [0], 1); - $info[' content '] =$body; - return $info; in}Else{ - return $data; to } +}
View Code
Parameter Description: Parameter 1 is the URL of the access, parameter 2 is the post data (not fill is get), Parameter 3 is the submitted $cookies, parameter 4 is whether to return $cookies.
Use the curl () function to synchronize a registered user between different sites