标签:
<?php
$ctime=150;
//自动创建cache目录来存放缓存的html文件
$path="cache/";
if(file_exists($path)){
}else{
mkdir($path,0777,true);
}
$fileinfo=$_SERVER[‘REQUEST_URI‘];
//$fn= pathinfo($fileinfo,PATHINFO_FILENAME);//输出myc
//echo $fn.‘<br>‘;
$cy= md5($fileinfo);//使html的前缀用md5的加密方式
$currpage=isset($_GET[‘p‘]) ? $_GET[‘p‘] : 1;
$id=isset($_GET[‘id‘]) ? $_GET[‘id‘] :1;
$cf=$path.$cy.$currpage.‘_‘.$id.‘.html‘;
ob_start();
// echo filemtime($cf);
// echo ‘<br>‘;
// echo time()-filemtime($cf);//判断缓存时间差
//判断缓存时间是否失效
if(file_exists($cf) && (time()-filemtime($cf))<$ctime){
include $cf;
exit;
}
?>
<?php
$html=ob_get_contents();
file_put_contents($cf, $html);
?>
<?php
$ctime=150;
//自动创建cache目录来存放缓存的html文件
$path="cache/";
if(file_exists($path)){
}else{
mkdir($path,0777,true);
}
$fileinfo=$_SERVER[‘REQUEST_URI‘];
// // $fn= pathinfo($fileinfo,PATHINFO_FILENAME);//输出myc
// echo $fn.‘<br>‘;
$cy= md5($fileinfo);//使html的前缀用md5的加密方式
$currpage=isset($_GET[‘p‘]) ? $_GET[‘p‘] : 1;
$id=isset($_GET[‘id‘]) ? $_GET[‘id‘] :1;
$cf=$path.$cy.$currpage.‘_‘.$id.‘.html‘;
ob_start();
// echo filemtime($cf);
// echo ‘<br>‘;
// echo time()-filemtime($cf);//判断缓存时间差
//判断缓存时间是否失效
if(file_exists($cf) && (time()-filemtime($cf))<$ctime){
include $cf;
exit;
}
require_once ‘inc/libs/Smarty.class.php‘;
include ‘inc/Db.class.php‘;
$db=new Db();
$s=new Smarty();
// echo $s::SMARTY_VERSION;
// echo smarty::SMARTY_VERSION;//输出版本号
$s->debugging=false;//关闭调试
$s->caching=false;//关闭缓存
$s->setTemplateDir(‘inc/html/‘);//设置模板文件路径
$s->setCacheDir(‘inc/cache/‘);//如果开启了缓存,设定缓存目录
$s->setCompileDir(‘inc/compile/‘);//设定模板编译后的路径
$f=isset($_GET[‘i‘]) ? $_GET[‘i‘] : ‘index‘;
switch ($f){
case ‘teacher‘;
// $trs=$db->query(‘teacher‘,‘*‘,"flag=‘y‘",‘order by sort desc‘);
// $db->css1();
$currpage=isset($_GET[‘p‘]) ? $_GET[‘p‘] :1;
$trs=$db->pager(‘teacher‘,$currpage,‘*‘,2,"flag=‘y‘",‘order by sort desc‘,‘i=teacher&‘);
$s->assign(‘trs‘,$trs);
$s->assign(‘page‘,$trs[1]);
break;
case ‘jy‘;
// $db->css1();
$currpage=isset($_GET[‘p‘]) ? $_GET[‘p‘] :1;
$srs=$db->pager(‘job‘,$currpage,‘*‘,6,‘1=1‘,‘order by id desc‘,‘i=jy&‘);
$s->assign(‘srs‘,$srs);
$s->assign(‘page‘,$srs[1]);
break;
case ‘newsarticle‘;
$id=$_GET[‘nid‘];
$db->updatenum(‘news‘,‘num=num+1‘,‘id=‘.$id);
$new=$db->query(‘news‘,‘*‘,‘id=‘.$id,‘order by id desc‘);
$s->assign(‘new‘,$new);
break;
case ‘news‘;
// $db->css1();
$cn=$_GET[‘cname‘];
$currpage=isset($_GET[‘p‘]) ? $_GET[‘p‘] :1;
$nn=$db->pager(‘news‘,$currpage,‘*‘,10,"flag=‘y‘ and cname=‘$cn‘",‘order by id desc‘,‘i=news&cname=‘.$cn.‘&‘);
$s->assign(‘nn‘,$nn);
default:
$trs=$db->query(‘teacher‘,‘*‘,‘1=1‘,‘order by sort desc‘,‘limit 2‘);
$s->assign(‘trs‘,$trs);
$zx=$db->query(‘news‘,‘*‘,"flag=‘y‘ and cname=‘网络营销资讯‘",‘order by id desc‘,‘limit 7‘);
$s->assign(‘zx‘,$zx);
$zs=$db->query(‘news‘,‘*‘,"flag=‘y‘ and cname=‘网络营销知识‘",‘order by id desc‘,‘limit 7‘);
$s->assign(‘zs‘,$zs);
$zjy=$db->query(‘news‘,‘*‘,"flag=‘y‘ and cname=‘最新就业信息‘",‘order by id desc‘,‘limit 7‘);
$s->assign(‘zjy‘,$zjy);
break;
$zxk=$db->query(‘news‘,‘*‘,"flag=‘y‘ and cname=‘网络营销课程‘",‘order by id desc‘,‘limit 7‘);
$s->assign(‘zxk‘,$zxk);
break;
}
$zjy=$db->query(‘news‘,‘*‘,"flag=‘y‘ and cname=‘最新就业信息‘",‘order by id desc‘,‘limit 7‘);
$s->assign(‘zjy‘,$zjy);
$s->assign(‘zxy‘,urlencode(‘最新就业信息‘));//解决ie里面的乱码问题
$s->assign(‘zxs‘,urlencode(‘网络营销资讯‘));
$s->assign(‘zss‘,urlencode(‘网络营销知识‘));
$s->assign(‘zsy‘,urlencode(‘网络营销课程‘));
$s->display($f.‘.html‘);
$html=ob_get_contents();
file_put_contents($cf, $html);
<?php
require_once ‘inc/libs/Smarty.class.php‘;
$s=new Smarty();
// echo $s::SMARTY_VERSION;
// echo smarty::SMARTY_VERSION;//输出版本号
$s->debugging=false;//关闭调试
$s->caching=true;//关闭缓存
$s->cache_lifetime=3600;//设定缓存时间
$s->setTemplateDir(‘inc/html/‘);//设置模板文件路径
$s->setCacheDir(‘inc/cache/‘);//如果开启了缓存,设定缓存目录
$s->setCompileDir(‘inc/compile/‘);//设定模板编译后的路径
$s->setConfigDir(‘inc/config/‘);//设定smarty配置文件的目录
$f=isset($_GET[‘i‘]) ? $_GET[‘i‘] : ‘index‘;
// $s->clearAllCache();
if($s->isCached($f.‘.html‘)){
$s->display($f.‘.html‘);
exit;
}
include ‘inc/Db.class.php‘;
$db=new Db();
switch ($f){
case ‘teacher‘;
// $trs=$db->query(‘teacher‘,‘*‘,"flag=‘y‘",‘order by sort desc‘);
// $db->css1();//这样引入会打乱页面
$currpage=isset($_GET[‘p‘]) ? $_GET[‘p‘] :1;
$trs=$db->pager(‘teacher‘,$currpage,‘*‘,2,"flag=‘y‘",‘order by sort desc‘,‘i=teacher&‘);
$s->assign(‘trs‘,$trs);
$s->assign(‘page‘,$trs[1]);
break;
case ‘jy‘;
// $db->css1();
$currpage=isset($_GET[‘p‘]) ? $_GET[‘p‘] :1;
$srs=$db->pager(‘job‘,$currpage,‘*‘,6,‘1=1‘,‘order by id desc‘,‘i=jy&‘);
$s->assign(‘srs‘,$srs);
$s->assign(‘page‘,$srs[1]);
break;
case ‘newsarticle‘;
$id=$_GET[‘nid‘];
$db->updatenum(‘news‘,‘num=num+1‘,‘id=‘.$id);
$new=$db->query(‘news‘,‘*‘,‘id=‘.$id,‘order by id desc‘);
$s->assign(‘new‘,$new);
break;
case ‘news‘;
// $db->css1();
$cn=$_GET[‘cname‘];
$currpage=isset($_GET[‘p‘]) ? $_GET[‘p‘] :1;
$nn=$db->pager(‘news‘,$currpage,‘*‘,10,"flag=‘y‘ and cname=‘$cn‘",‘order by id desc‘,‘i=news&cname=‘.$cn.‘&‘);
$s->assign(‘nn‘,$nn);
default:
$trs=$db->query(‘teacher‘,‘*‘,‘1=1‘,‘order by sort desc‘,‘limit 2‘);
$s->assign(‘trs‘,$trs);
$zx=$db->query(‘news‘,‘*‘,"flag=‘y‘ and cname=‘网络营销资讯‘",‘order by id desc‘,‘limit 7‘);
$s->assign(‘zx‘,$zx);
$zs=$db->query(‘news‘,‘*‘,"flag=‘y‘ and cname=‘网络营销知识‘",‘order by id desc‘,‘limit 7‘);
$s->assign(‘zs‘,$zs);
$zjy=$db->query(‘news‘,‘*‘,"flag=‘y‘ and cname=‘最新就业信息‘",‘order by id desc‘,‘limit 7‘);
$s->assign(‘zjy‘,$zjy);
break;
$zxk=$db->query(‘news‘,‘*‘,"flag=‘y‘ and cname=‘网络营销课程‘",‘order by id desc‘,‘limit 7‘);
$s->assign(‘zxk‘,$zxk);
break;
}
$zjy=$db->query(‘news‘,‘*‘,"flag=‘y‘ and cname=‘最新就业信息‘",‘order by id desc‘,‘limit 7‘);
$s->assign(‘zjy‘,$zjy);
$s->assign(‘zxy‘,urlencode(‘最新就业信息‘));//解决ie里面的乱码问题
$s->assign(‘zxs‘,urlencode(‘网络营销资讯‘));
$s->assign(‘zss‘,urlencode(‘网络营销知识‘));
$s->assign(‘zsy‘,urlencode(‘网络营销课程‘));
$s->display($f.‘.html‘);
{nocache}
<h1>{date(‘Y-m-d H:i:s‘)}</h1>
{/nocache}
标签:
原文地址:http://www.cnblogs.com/lsr111/p/4629019.html