<?phpheader ("content-type:text/html; Charset=utf-8 "); /*** Curl Passes data */class Curl {private $curl _resource;private $url = ';p rivate $input = Array ();p rivate $curl _error = ';p ri vate $curl _info = ";p ublic $response;p ublic function __construct ($url) {$this->url = $url;} Public Function Get_info () {return array (' url ' = = $this->url, ' input ' = = $this->input, ' Curl_error ' =>$ This->curl_error, ' curl_info ' = $this->curl_info);} Private Function Connect () {$this->curl_resource = Curl_init (); curl_setopt ($this->curl_resource, Curlopt_ HEADER, 0); Filter HTTP Header curl_setopt ($this->curl_resource,curlopt_returntransfer, 1);//Display Output curl_setopt ($this->curl_ Resource, Curlopt_timeout, 30); Set the timeout limit to prevent the dead loop}public function post ($input) {$this->connect (); $input = (array) $input; $this->input = $input; $input = Http_build_query ($input); Generates a UrlEncode request string based on an array curl_setopt ($this->curl_resource, Curlopt_url, $this->url); curl_setopt ($this-≫curl_resource,curlopt_post,true); Post transmission Data curl_setopt ($this->curl_resource,curlopt_postfields, $input); Post transmits data $this->curl_error = Curl_error ($this->curl_resource); $this->curl_info = curl_getinfo ($this->curl_resource); $this->response = curl_exec ($this->curl_resource); Curl_close ($this->curl_resource); return $this->response;} Public function Get ($input) {$this->connect (); $input = (array) $input; $this->input = $input; $input = $this->url. '? '. Http_build_query ($input); curl_setopt ($this->curl_resource, Curlopt_url, $input); $this->response = curl_exec ($this->curl_resource); Curl_close ($this->curl_resource); return $this->response;}} $curl = new Curl (' http://www.test.com/index.php ');p rint_r ($curl->post (' Post pass Data ')) Var_dump ($curl->get_info ());p Rint_r ($curl->get (' Get Pass Data ')), Var_dump ($curl->get_info ());
PHP Curl Pass Data