Objective:
I am learning PHP, do this is also learn from Baidu examples and other programs. Interested small partners can communicate with each other
First, the HTML query page
Then it's the query Display page (using the Curl operation)
1<?PHP2 Header(' Content:text/html;charset:utf-8 ');3 $ch=curl_init ();4 $phone=isset($_post[' Phone ']?$_post[' Phone ']:false;5 $url= ' http://apis.baidu.com/apistore/mobilenumber/mobilenumber?phone= '.$phone;6 $header=Array(7' Apikey: Fill in your API ',8 );9 //add Apikey to HeaderTencurl_setopt ($ch, Curlopt_httpheader,$header); Onecurl_setopt ($ch, Curlopt_returntransfer, 1); A //executing an HTTP request -curl_setopt ($ch, Curlopt_url,$url); - $res= Curl_exec ($ch); the - $jsondata=json_decode ($res,true); - if($jsondata&&$jsondata[' Errnum ']==0){ - Echo' Query status: ',$jsondata[' retmsg '], ' <br/> '; + Echo' Enquiry number: ',$jsondata[' Retdata '] [' Phone '], ' <br/> '; - Echo' Query number segment: ',$jsondata[' Retdata '] [' prefix '], ' <br/> '; + Echo' Operator: ',$jsondata[' Retdata '] [' Supplier '], ' <br/> '; A Echo' Attribution to the province: ',$jsondata[' Retdata '] [' Province '], ' <br/> '; at Echo' Attribution to the city: ',$jsondata[' Retdata '] [' City '], ' <br/> '; - Echo' Number package: ',$jsondata[' Retdata '] [' Suit '], ' <br/> '; - } - Else{ - Echo' <script>alert ("Query Failed"); location.href= "index.html" </script> '; -}
return result is
Query Status: Success Query number:15210011578 Query number segment:1521001 Operator: Mobile Attribution Province: Beijing City: Beijing number package: 152 Card
Mobile phone number attribution to query