Library
public function doRequest($url, $para) { do { if(extension_loaded('curl')) { $ch = curl_init(); $options = array( CURLOPT_URL => $url, CURLOPT_HEADER => 0, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $para, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSLVERSION => 1, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'], ); curl_setopt_array($ch, $options); $data = curl_exec($ch); $info = curl_getinfo($ch); $error = curl_error($ch); curl_close($ch); if(get_magic_quotes_gpc()) { $data = stripslashes($data); } $decode = json_decode($data, true); if(json_last_error() === JSON_ERROR_NONE) { $err = array( 'status' => 'success', 'results' => $info, ); } else { $err = array( 'status' => 'failed', 'results' => '傳回值非JSON 類型', ); } } else { $err = array( 'status' => 'failed', 'results' => '請開啟PHP Curl 拓展', ); } return $err; } while(0); }
Controller
public function how_old() { $url = config_item('how_old_url'); $data = array( 'isTest' => false, 'faceName' => 'Test', 'faceUrl' => 'http://www.sinaimg.cn/dy/slidenews/4_img/2015_12/704_1579346_230297.jpg', ); $this->load->library('cuiqg'); var_dump( $this->cuiqg->doRequest($url, $data))]; }
Browser
奇怪 沒有任何 列印 他是怎麼顯示出來的 ,在一個 gettype() doRequest() $data 是bool 類型的 怎麼處理, 還有就是這些逸出字元怎麼去掉 ~_~||
回複內容:
Library
public function doRequest($url, $para) { do { if(extension_loaded('curl')) { $ch = curl_init(); $options = array( CURLOPT_URL => $url, CURLOPT_HEADER => 0, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $para, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_SSLVERSION => 1, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'], ); curl_setopt_array($ch, $options); $data = curl_exec($ch); $info = curl_getinfo($ch); $error = curl_error($ch); curl_close($ch); if(get_magic_quotes_gpc()) { $data = stripslashes($data); } $decode = json_decode($data, true); if(json_last_error() === JSON_ERROR_NONE) { $err = array( 'status' => 'success', 'results' => $info, ); } else { $err = array( 'status' => 'failed', 'results' => '傳回值非JSON 類型', ); } } else { $err = array( 'status' => 'failed', 'results' => '請開啟PHP Curl 拓展', ); } return $err; } while(0); }
Controller
public function how_old() { $url = config_item('how_old_url'); $data = array( 'isTest' => false, 'faceName' => 'Test', 'faceUrl' => 'http://www.sinaimg.cn/dy/slidenews/4_img/2015_12/704_1579346_230297.jpg', ); $this->load->library('cuiqg'); var_dump( $this->cuiqg->doRequest($url, $data))]; }
Browser
奇怪 沒有任何 列印 他是怎麼顯示出來的 ,在一個 gettype() doRequest() $data 是bool 類型的 怎麼處理, 還有就是這些逸出字元怎麼去掉 ~_~||
$url="http://how-old.net/Home/Analyze"; $data = array( 'isTest' => false, 'faceName' => 'Test', 'faceUrl' => 'http://www.sinaimg.cn/dy/slidenews/4_img/2015_12/704_1579346_230297.jpg', ); function post( $url, $params, $cookie ="") { $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_AUTOREFERER, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params)); $result = curl_exec($curl); curl_close($curl); return $result; }$result = post($url,$data);var_dump(json_decode(json_decode($result)));