forked from helloxz/zdir
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.php
More file actions
102 lines (88 loc) · 2.49 KB
/
Copy pathcache.php
File metadata and controls
102 lines (88 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED);
include_once("./config.php");
//载入zdir类
include_once("./functions/zdir.class.php");
@$del = $_GET['del'];
//缓存文件夹路径
$cachefile = "./functions/caches/indexes.html";
//获取文件修改时间
@$ftime = filemtime($cachefile);
@$cachetime = date('Y-m-d H:i:s',$ftime);
(int)@$ftime = date('YmdH',$ftime);
(int)$thetime = date('YmdH',time());
//计算时差
$diff = $thetime - $ftime;
//删除缓存文件
if($del == 'cache') {
unlink($cachefile);
header("location:./cache.php");
exit;
}
//判断缓存文件是否存在
if((!file_exists($cachefile)) || ($diff > 24)){
$url = get_url();
$curl = curl_init($url."indexes.php");
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36");
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
#设置超时时间,最小为1s(可选)
#curl_setopt($curl , CURLOPT_TIMEOUT, 1);
$html = curl_exec($curl);
curl_close($curl);
$myfile = fopen($cachefile,"w") or die("Unable to open file!");
fwrite($myfile, $html);
fclose($myfile);
$cache = file_get_contents($cachefile);
}
else{
$cache = file_get_contents($cachefile);
}
//获取页面URL
function get_url(){
$port = $_SERVER["SERVER_PORT"];
//对端口进行判断
switch ( $port )
{
case 80:
$protocol = "http://";
$port = '';
break;
case 443:
$protocol = "https://";
$port = '';
break;
default:
$protocol = "http://";
$port = ":".$port;
break;
}
//或如URI
$uri = $_SERVER["REQUEST_URI"];
$uri = str_replace("cache.php","",$uri);
//组合为完整的URL
$domain = $protocol.$_SERVER['SERVER_NAME'].$port.$uri;
return $domain;
}
?>
<!--载入页头-->
<?php include_once( './template/header.php' ); ?>
<!--中间内容部分-->
<div class="layui-container">
<div class="layui-row">
<div class="layui-col-lg10 layui-col-md-offset1">
<div id="cache">
<?php
echo "<h1>文件索引 - 该数据缓存于$cachetime</h1><br />";
echo $cache;
?>
</div>
</div>
</div>
</div>
<!--中间内容部分END-->
<!--载入页脚-->
<?php include_once( './template/footer.php' ); ?>