源码
<?php
$max_len = 9;
$CounterFile = "counter.dat";
if(!file_exists($CounterFile)){
$counter = 0;
$cf = fopen($CounterFile,"w");
fputs($cf,'0');
fclose($cf);
}else{
$cf = fopen($CounterFile,"r");
$counter = trim(fgets($cf,$max_len));
fclose($cf);
}
$counter++;
$cf = fopen($CounterFile,"w");
fputs($cf,$counter);
fclose($cf);
?>
<script type="text/javascript">
function runtime(){
X = new Date("1/16/2022 17:16:54");
Y = new Date();
T = (Y.getTime()-X.getTime());
M = 24*60*60*1000;
a = T/M;
A = Math.floor(a);
b = (a-A)*24;
B = Math.floor(b);
c = (b-B)*60;
C = Math.floor((b-B)*60);
D = Math.floor((c-C)*60);
alert("网站建立: "+A+"天"+B+"时"+C+"分"+D+"秒"+"\n 该网站已被浏览:<?php echo "$counter";?>次")
}
runtime()
</script>
两个代码是在一个PHP页面上的,PHP放在HTML前面,JS放到后面效果会更好
|