$handle = fopen($file_path, "r");
while (!feof($handle)) {
$content = fgets($handle, 4096); //读取一行
echo $content; //输出到缓冲区,即php://stdout。达到缓冲区设置值后由tcp传给浏览器进行输出 一般到512字节就会通过网络输出给浏览器
} //by www.
fclose($handle);
}
?>
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
Header("Content-type: application/octet-stream"); //响应内容类型
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($filename). ' bytes');
Header('Content-Disposition: attachment; filename='.$filename); //HTTP响应头
?>
本文链接:http://www.cnblogs.com/linuxnotes/p/3229181.html,转载请注明。
天气数据是通过采集中国气象网站的。本来中国天气网站也给出了数据的API接口,接下来为大家介绍下用php来写一个天气预报的模块,感兴趣的朋友可以参考下
用php来写一个天气预报的模块
天气数据是通过采集中国气象网站的。本来中国天气网站也给出了数据的API接口。以下是API的地址。返回的数据格式为json格式。
1. http://www.weather.com.cn/data/sk/101010100.html
2. http://www.weather.com.cn/data/cityinfo/101010100.html
3. http://m.weather.com.cn/data/101010100.html
URL中的数字”101010100“是城市代码。所以可以先列出每个城市的城市代码,然后php程序接收到了城市代码,再去组装URL,在通过URL来显示该城市的实时天气。
index.php
header("Content-Type:text/html;charset=utf-8");
?>
<html>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<head>
<title>天气预报-www.-</title>
<script type="text/javascript" src="/blog_article/ajax.js"></script>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
function getCityId(){
var http_request=createAjax();
var url="weatherforecast.php"
var data="cityid="+$("cityId").value;
http_request.onreadystatechange=getWetherInfo;
http_request.open("post",url,true);
http_request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
http_request.send(data);
function getWetherInfo(){
if(http_request.readyState==4 && http_request.status==200){
var info=http_request.responseText;
$("weatherinfo").innerHTML=info;
}
}
}
</script>
</head>
<body>
<select name="cityId" onchange="getCityId();" id="cityId">
<option>--请选择城市--</option>
<option value="101010100">北京</option>
<option value="101020100">上海</option>
<option value="101030100">天津</option>
<option value="101040100">重庆</option>
<option value="101280101">广州</option>
</select>
<span id="weatherinfo"></span>
</body>
</html>
weatherforecast.php
header("Content-Type:text/html;charset=utf-8");
header("Cache-Control:no-cache");
if (isset($_POST['cityid'])){
$cityid=$_POST['cityid'];
$url=$url="http://www.weather.com.cn/data/sk/".$cityid.".html";
}else {
$url="http://www.weather.com.cn/data/sk/101010100.html";
}
$weatherInfo_json=file_get_contents($url);
$weatherInfo=json_decode($weatherInfo_json,true);
$cityName=$weatherInfo['weatherinfo']['city'];
$cityTemp=$weatherInfo['weatherinfo']['temp'];
$cityWd=$weatherInfo['weatherinfo']['WD'];
$cityWs=$weatherInfo['weatherinfo']['WS'];
$cityTime=$weatherInfo['weatherinfo']['time'];
$citySD=$weatherInfo['weatherinfo']['SD'];
echo $weatherinfo="城市名字:$cityName,气温:$cityTemp,风向:$cityWd";
?>
本文链接:http://www.cnblogs.com/cfinder010/p/3229178.html,转载请注明。
效果演示: http://pcik.7di.net/pcik_reg
百度的效果演示: https://passport.baidu.com/cgi-bin/genimage?captchaservice63636236364e55367233302f31673844526b664451665a5a4d4977466974376b707a754466777934697449455561625171346c725055444b51734a35376d2b4f744b6d303238315341382b354675344c3153745869487252376169752b437450515138574972436752584f53717849726f48593258666c373574593753614f4d32703831724e51722b694a31756b67467137644c30506979496639594e504931536732687a5a505379305544554245724f76694a307247632b4f76426165663144732b595359394950413470476453787865564f6b506e674f7537637264526d716541377a384b487445624f365a4774657a58502b7347703763696d5752614171615747784e5a6c5042336634766a5049766853365974444258577968645a4f654f55
由於我水平不行,所以做不到百度那麼絢的效果,請海涵
验证码图片由PHP生成的多帧构成,所以验证码是一个真实存在的可以动的gif图
使用方法非常简单:
說明:
Gif驗證碼創建類
作者:
7di.net QQ群:223494678
调用:
<img src="/blog_article/class_code/code/code.html" onclick="this.src=/blog_article/this.src'&'+Math.round(Math.random(0)*1000)" >
验证:
IF(!isSet($_SESSION['code']) Or StrToLower($_SESSION['code'])!=StrToLower($cod)){
throw New Exception('Error:'.__LINE__.',驗證碼錯誤!');Die();
}unSet($cod,$_SESSION['code']);
下载地址: http://download.csdn.net/detail/sibang/5852531
本文链接:http://www.cnblogs.com/see7di/p/3230291.html,转载请注明。