<%
dim images(20)
CountFile=Server.MapPath("count.txt")
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
Set Out=FileObject.OpenTextFile(CountFile,1,FALSE,FALSE)
counter=Out.ReadLine
Out.Close
SET FileObject=Server.CreateObject("Scripting.FileSystemObject")
Set Out=FileObject.CreateTextFile(CountFile,TRUE,FALSE)
Application.lock
If(session("dl")="") Then
counter= counter + 1
session("dl")=1
End if
Out.WriteLine(counter)
Application.unlock
countlen=len(counter)
for i=1 to countlen
images(i)=mid(counter,i,1)
response.write images(i)
next
Out.Close
%>
再加一个文本文件count.txt就OK了
dim images(20)
CountFile=Server.MapPath("count.txt")
Set FileObject=Server.CreateObject("Scripting.FileSystemObject")
Set Out=FileObject.OpenTextFile(CountFile,1,FALSE,FALSE)
counter=Out.ReadLine
Out.Close
SET FileObject=Server.CreateObject("Scripting.FileSystemObject")
Set Out=FileObject.CreateTextFile(CountFile,TRUE,FALSE)
Application.lock
If(session("dl")="") Then
counter= counter + 1
session("dl")=1
End if
Out.WriteLine(counter)
Application.unlock
countlen=len(counter)
for i=1 to countlen
images(i)=mid(counter,i,1)
response.write images(i)
next
Out.Close
%>
再加一个文本文件count.txt就OK了
楼主,你就用cookies或者session.通过判断cookies和session是否存在,如果不存在就计数,存在就跳过不就ok了?
楼主,你就用cookies或者session.通过判断cookies和session是否存在,如果不存在就计数,存在就跳过不就ok了?
这个我以前仿照别人做了一个,但是不能记数,刷新是不记数了,但是session老不消失,就算把session过期设了5都没有用,大家帮我看看怎么回事。
<?php
session_start(); ?>
<?php
//File name
//That's it
$file = "counter.txt ";
if( ! file_exists( "$file" ) ) {
touch( "$file" );
chmod("$file",0777);
$fp=fopen("$file","r+");
fseek($fp,0);
$compteur = 0;
fputs($fp,$compteur);
}if( is_readable( "$file") and is_writable( "$file") ) {$fp=fopen("$file","r+");
$compteur=fgets($fp,9999);
fseek($fp,0);
if (!isset($_SESSION['counter']))
{$compteur++;
$_SESSION['counter'] = 1; }
fputs($fp,$compteur);
fclose($fp);
print $compteur;
} else {
chmod("$file",0777);
}
?>这个程序做成后,在tmp中删除session值再刷新可以记数,不删除的话,死活不记数。大家看看是不是chmod有问题啊
session.gc_maxlifetime = 5
其中session保存的文件夹是c:\winnt\tmp,我在这个文件夹里面把session值删掉,他该死的就记数,不删,他该死的就死活刷新不记数,我曾经试过隔了3,4个小时再去刷新,就是不记数。没办法了,来求救了,^_^。
这不就是你要的效果吗?
这个有具体一点的程序吗,我还在学习中,需要有例程引导另外,那个session.gc_maxlifetime = ×××
是控制什么的啊,我设了什么用也没有啊
chmod()是php的函数,并不是linux的同名命令
<?php
$filename = 'test.txt';
$fp = fopen($filename,'w');
fclose($fp);printf("%o", fileperms($filename)); // 100666
chmod($filename,0444);
clearstatcache();
printf("%o", fileperms($filename)); // 100444
?>
完了,文件test.txt删不掉了!session.gc_maxlifetime = xxx 是通知操作系统的gc进程,session的临时文件可在最后访问时间之后的xxx秒钟删除。而gc进程是操作系统的“清洁工”他定时删除允许他删除的临时文件总量的3%左右的文件。
遗憾的是,在win32系统下他并不理睬php的这一设置。而在linux下也并非一定有效楼主
如果你将
if (!isset($_SESSION['counter'])) {
$compteur++;
$_SESSION['counter'] = 1;
}
改成
if(!isset($_SESSION['counter']) || $_SESSION['counter']-time() > 10) {
$compteur++;
$_SESSION['counter'] = time();
}
那么不就可以每10秒刷新计数了吗?不建议用cookie。假如人家禁用了cookie呢?