点击链接时没有工作

时间:2009-06-16 06:35:20

标签: php

$file = ".$dirN/$filename.";
                 $count_my_page = (".$dirname1/$filename.$extens");
                 if(fopen(".$file.","r"))
                 {
                    $hits = file($count_my_page);
                    $nHits = ((int) $hits[0]) + 1;
                    $fp = fopen($count_my_page , "w");
                    fputs($fp , $nHits . "");
                    fclose($fp);
                    echo $nHits;

                  }

我希望只有在我读取文件时才会增加计数,但是在刷新文件链接的页面时会发生其他情况。

2 个答案:

答案 0 :(得分:1)

单击链接并刷新页面只是客户端上的不同操作,与服务器没有区别;它只是看到一个HTTP请求。

我不认为在单击链接时不使用JavaScript设置某种表单变量就可以完成此操作。

答案 1 :(得分:0)

我不确定我是否理解了这个问题,但您可以尝试以下方法:

向用于读取文件的链接添加参数,如:

http://www.localhost.de/readfile.php?read=true

在你的count方法中检查参数:

if ($_request['read'] === true) { 
   // count
   -> do an redirect to remove the parameter, or set it to false ..
} else {
   // nothing
}
相关问题