tags:

views:

47

answers:

2
$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;

         }

I want the count to increase only when i read the file, but it happens other wise on refreshing the page where the link of the file is present.

+1  A: 

Clicking a link and refreshing a page are only differt actions on the client, there's no difference to the server; it just sees a HTTP request.

I don't think this can be done without using JavaScript to set some kind of form variable when the link is clicked.

Michael Borgwardt
A: 

Hi, iam not sure if i understand the question but you can try the following :

Add an parameter to the link used to read the file like :

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

in your count method check for the parameter:

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