//如果使用静态页面则取得当前页面的路径,并判断是否存在静态文件和文件的生成日期时间戳与当前日期时间戳是否相差$spacing这么多,有则跳转,无有则生成静态文件路径
function
UseHtmlPage(
$isHTMLModel
,
$spacing
){
if
(
$isHTMLModel
){
$paramet
=
""
;
$paramet
=
$_SERVER
[
'QUERY_STRING'
];
if
(
$paramet
!=
""
)
$paramet
=
"="
.
str_replace
(
"="
,
"-"
,
str_replace
(
"&"
,
"_"
,
$_SERVER
[
'QUERY_STRING'
])).
""
;
$HtmlPath
=dirname(
$_SERVER
[
"SCRIPT_FILENAME"
]).
"\\html"
.
str_replace
(
".php"
,
$paramet
.
".html"
,
str_replace
(
"/"
,
"\\"
,
$_SERVER
[
"PHP_SELF"
]));
$Path
=
"/html"
.
str_replace
(
".php"
,
$paramet
.
".html"
,
$_SERVER
[
"PHP_SELF"
]);
if
(
file_exists
(
$HtmlPath
)){
$one
=
strtotime
(
date
(
'r'
,
filemtime
(
$HtmlPath
)));
//文件之前 时间戳
$two
= time();
//系统现在 时间戳
$cle
=
$two
-
$one
;
//得出时间戳差值
if
(
$H
<
$spacing
) {header(
"Location: "
.
$Path
);}
}
return
$HtmlPath
;
}
}
//如果使用静态页面并且有静态文件路径,则把当前页面的缓存写到静态文件中
function
CreateHtmlPage(
$HtmlPath
,
$isHTMLModel
){
if
(
$isHTMLModel
) WriteHtml(
$HtmlPath
);
}
//把当前页面的缓存写到静态文件中
function
WriteHtml(
$filepath
){
if
(
$filepath
!=
""
){
$content
= ob_get_contents();
//取得php页面输出的全部内容
ob_flush();
@unlink(
$filepath
);
$fp
=
fopen
(
$filepath
,
"w"
);
//创建一个文件,并打开,准备写入
fwrite(
$fp
,
$content
);
//把php页面的内容全部写入
fclose(
$fp
);
}
}