Now a variety of Web applications, as a programmer, how can not be a defensive? "PHP implementation of mobile phone attribution Search Video Tutorial" will take you from 0 to develop a complete Web application, from framework to process analysis and data caching, I believe you learned this lesson after the harvest is not only learned to develop an application.
Course Play Address: http://www.php.cn/course/412.html
The teacher's lecture style:
The teacher lively image, witty witty, witty, touching. A vivid image of the metaphor, like the finishing touch, to the students to open the door of wisdom, a proper sense of humor, attracting students to smile, such as drinking a cup of glycol wine, to the aftertaste and nostalgia, the philosopher's motto, culture of the proverbs from time and again interspersed in the middle, give people to think and alert.
The more difficult part of this video is the API request data:
Method One (if post, applies only to one-dimensional arrays)
/** * Curl Send HTPP Request * can send Https,http,get way, post mode, post data send * /Public Function Datarequest ($url, $ Https=true, $method = ' get ', $data =null) { //Initialize curl $ch = Curl_init ($url); The string is not output directly, and a variable is stored curl_setopt ($ch, Curlopt_returntransfer, 1); HTTPS request if ($https = = = True) { //Ensure HTTPS request can request success curl_setopt ($ch, curlopt_ssl_verifypeer,false); curl_setopt ($ch, Curlopt_ssl_verifyhost,false); } Post request if ($method = = ' Post ') { curl_setopt ($ch, curlopt_post,true); curl_setopt ($ch, Curlopt_postfields, $data); } Send request $str = curl_exec ($ch); $aStatus = Curl_getinfo ($ch); Close connection curl_close ($ch); if (Intval ($aStatus ["http_code]) ==200) { return Json_decode ($STR); } else{ return false; } }
Method Two (if the Post method, for two-dimensional array)
/** * @Purpose: Curl sends HTPP request, can send Https,http,get way, post mode, post data send * @Author: Chrdai * @Method name:send Databycurl () * @parameter: string $url routed URL * Boolean $HTTPS use HTTPS * String $method Pass Method * Array $data data * @return: Returns the result returned successfully, False */function Senddat Abycurl ($url, $https =true, $method = ' get ', $data =null) {//Initialize curl $ch = Curl_init ($url); The string is not output directly, and a variable is stored curl_setopt ($ch, Curlopt_returntransfer, 1); HTTPS request if ($https = = = True) {//Ensure HTTPS request can request success curl_setopt ($ch, Curlopt_ssl_verifypeer,false); curl_setopt ($ch, Curlopt_ssl_verifyhost,false); }//Post request if ($method = = ' Post ') {curl_setopt ($ch, curlopt_post,true); The required array is processed with the http_bulid_query () function, and a two-dimensional array can be passed curl_setopt ($ch, Curlopt_postfields, Http_build_query ($data)); }//Send request $STR = curl_exec ($ch); $aStatus = Curl_getinfo ($ch); Shut downConnection Curl_close ($ch); if (Intval ($aStatus ["Http_code"]) ==200) {return json_decode ($STR); }else{return false; }}
Method Three (if post, applies to pass JSON)
/** * @Purpose: Curl sends HTPP request, can send Https,http,get way, post mode, post data send * @Author: Chrdai * @Method name:send Databycurl () * @parameter: string $url routed URL * Boolean $HTTPS use HTTPS * String $method Pass Method * Array $jsonStr The JSON string to be passed * @return: Returns the result returned successfully, False */func tion Senddatabycurl ($url, $https =true, $method = ' get ', $jsonStr =null) {//Initialize curl $ch = Curl_init ($url); The string is not output directly, and a variable is stored curl_setopt ($ch, Curlopt_returntransfer, 1); HTTPS request if ($https = = = True) {//Ensure HTTPS request can request success curl_setopt ($ch, Curlopt_ssl_verifypeer,false); curl_setopt ($ch, Curlopt_ssl_verifyhost,false); }//Post request if ($method = = ' Post ') {curl_setopt ($ch, curlopt_post,true); curl_setopt ($ch, Curlopt_postfields, $JSONSTR); Just use an HTTP header to pass the JSON! curl_setopt ($ch, Curlopt_httpheader, Array (' Content-type:application/json; chArset=utf-8 ', ' content-length: '. Strlen ($JSONSTR))); }//Send request $STR = curl_exec ($ch); $aStatus = Curl_getinfo ($ch); Close connection curl_close ($ch); if (Intval ($aStatus ["Http_code"]) ==200) {return json_decode ($STR); }else{return false; }}