Counter should not Increment when Page Refresh HELP
Posted: Thu Jun 26, 2008 7:54 pm
Hi guys,
I made a Hit Counter for my Hw assignment that basically counts everytime someone goes to the site. Here's the site just in case http://php.crc.losrios.edu/~w0957358/counter_a3.php . My assignment is basically done but for extra credit. We have to make it where the counter does not Increment when someone presses Refresh. It should only increase if someone visits newly fresh page and I do not have a single clue where I should start from. I am a total noob to this stuff. Please help if possible. Here is the code that I have typed.
Thank You
I made a Hit Counter for my Hw assignment that basically counts everytime someone goes to the site. Here's the site just in case http://php.crc.losrios.edu/~w0957358/counter_a3.php . My assignment is basically done but for extra credit. We have to make it where the counter does not Increment when someone presses Refresh. It should only increase if someone visits newly fresh page and I do not have a single clue where I should start from. I am a total noob to this stuff. Please help if possible. Here is the code that I have typed.
Code: Select all
<?php
$fp = fopen('counter.txt',"r");
$num = fgets($fp);
fclose($fp);
print ("You have visited this page $num times.");
$fp = $num++;
$fp = fopen('counter.txt',"w");
fwrite($fp,$num);
fclose($fp);
?>