I wrote a PHP5 based on curl, the function is relatively simple, more suitable for learning. If you really want to apply it, it is definitely recommended that Snoopy is too powerful. Although it is not on the basis of curl. Transfer from HTTP://XIAOWAI.GENTIEBA.COM/NODE/33
<?PHPclassMy_curl { Public function__construct () {!extension_loaded(' Curl ') &&Exit(' curl extension is not loaded, program terminates run ' ); Header(' content-type:text/html; Charset=utf-8 ' ); } Public functionGo$url,$vars= ' ') { $ch=Curl_init (); $array[Curlopt_url] =$url; $array[Curlopt_header] =false; $array[Curlopt_returntransfer] =true; $array[Curlopt_followlocation] =true; if(!Empty($vars )) { $postfields=$this->render_postfields ($vars);//URL to generate Urlcode $array[Curlopt_post] =true; $array[Curlopt_postfields] =$postfields; } //determine if there is a cookie, and some words are used directly if($_cookie[' Cookie_jar '] | |Is_file($_cookie[' Cookie_jar '] )) { $array[Curlopt_cookiefile] =$_cookie[' Cookie_jar '];//The cookie is judged here}Else { $cookie _jar=Tempnam('/tmp ', ' Cookie ');//generate a cookie file $array[Curlopt_cookiejar] =$cookie _jar;//Write Cookie Information Setcookie(' Cookie_jar ',$cookie _jar);//Save Cookie Path} curl_setopt_array ($ch,$array);//Incoming Curl parameter $content= Curl_exec ($ch);//ExecutionCurl_close ($ch);//Close return $content;//return } protected functionRender_postfields ($vars) { foreach($vars as $key=$values ) { $postdata.=UrlEncode($key) . "=" .UrlEncode($values) . "&"; } return $postdata; }}?>
How to use
<?PHPif($_post[' Email ']&&$_post[' Password ']){ include' Curl_class.php ';$curl=NewMy_curl ();$vars[' email '] =$_post[' Email '];$vars[' password '] =$_post[' Password '];//$vars [' done '] = '/';//$vars [' submit '] = ' login ';Echo $curl->go (' Http://www.renren.com/PLogin.do ',$vars ); }Else{?>class= "Login-form" id= "LoginForm" method= "POST" > <input type= "text" id= "email" name= "email"/> <input Type= "text" id= "password" name= "password"/> <input type= "Submit" tabindex= "4" value= "Login"class= "Input-submit" id= "Login" > </form> A simple PHP curl class