今天发现服务器上不能直接窃取北仑之窗天气预报页面.
于是花了点时间写了个天气预报程序,提提意见 :)
/*
文件名 get.php
运行环境---php 4.3
php.ini set:magic_quotes_gpc:on[默认设置]
register_globals:on [默认设置]
测试环境 window 2000 +IIS 5.0 + php 5.1
测试地址 : http://zjs.longtengcn.com/get.php
*/
/*
首先得到服务器的时间
*/
$filename="tqyb.txt"; //静态文件名,如果是写入php文件使用$url="http://www.xgsy.net/get.asp";
/*窃取地址,这里可以修改,现使用小港实验学校地址,测试地址为大契中学地址 */
$nowtimed=date('Y-m-d',time()+8*3600); //当前日期对访问量小每天上下午达不到2次的网站,需要加入日期比较.这里略
$nowtimeh=date("h:m:s",time()+8*3600);//当前时间
if(file_exists($filename)) //存在文件
{
require_once($filename);
$filemod=filemtime($filename);
$lastmodd=date('Y-m-d',$filemod+8*3600);
$lastmodh=date('h:m:s',$filemod+8*3600);
//判断
$lasthour=explode(":",$lastmodh); //修改时间
$nowhour=explode(":",$nowtimeh);//当前时间
$lasth=(int)$lasthour[0];
$nowh=(int)$nowhour[0];
//比较
if(($lasth>=1 && $nowh>=6 && $nowh<=11) || ($nowh>=17 && $lasth<17))
{
//这段时间 进行窃取
del_file($filename);
setweather($filename,$url);
}
}
//不存在文件
else
{
setweather($filename,$url);
}
//天气预报
function setweather($file,$url)
{
$str=@file_get_contents($url);
/*
$al=explode("",$str);
$newstr=strip_tags($al[1]);
$newstr="\$tqyb=\"".$newstr."\";";
//这里为调用北仑之窗过滤代码,略过
*/
$newstr=$str;
if($h=fopen($file,'w'))
{
@fwrite($h,$newstr) or die("写入文件失败");
//感觉这个速度要快些
// @fputs($h,$newstr) or die("文件写入失败");
fclose($h);
}
else
{
die('写入文件失败.请检查文件夹是否有权限');
}
}
//删除文件
function del_file($filename)
{
if(file_exists($filename))
{
@unlink($filename);
}
}
//
if(file_exists($filename))
{
require_once($filename);
}
?>
//今天回去了,明天把这几天在windows上配置php5的心得写写.
//修改了下因获取的时间是格林威时间,需要转化为北京时间.一下子没想起.