PHP 本地实现 接口查询天气等功能

 1 <?php
 2     header("content-type:text/html; charset = utf-8");
 3 
 4     // 
 5     // 
 6 
 7         $url = "http://api.94qing.com/";
 8         $cookie_file  =  tempnam(' ./temp','cookie');
 9 
10         $ch = curl_init($url);
11         curl_setopt($ch, CURLOPT_HEADER,0);
12         curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//0显示,1不显示
13         curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file);//保存cookie
14         $data = curl_exec($ch);
15         curl_close($ch);
16 
17         $url = "http://api.94qing.com/?type=weather&msg=合肥";//修改合肥为你自己的城市
18         $headers = array("Referer:http://api.94qing.com/");
19 
20         $ch = curl_init($url);
21 
22         curl_setopt($ch, CURLOPT_HEADER,0);
23         curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//0显示,1不显示
24         curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
25         curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);//保存cookie
26         $data = curl_exec($ch);
27         curl_close($ch);
28          echo $data;
29 ?>

posted @ 2013-12-14 11:45  任Jobs  阅读(347)  评论(0编辑  收藏  举报