...

View Full Version : Hit Counter Resetting



IFeelYourPain
07-18-2008, 06:13 AM
I have a simple hit counter, but for some reason it resets itself every now and then. Here is the counter:


<?php
$visits = ("hits.txt");
$hits = file($visits);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
echo $hits[0];
?>

oesxyl
07-18-2008, 06:31 AM
<?php
$visits = "hits.txt";
// open the file and read how many visitors was
$fp = fopen($visits,"r");
$hits = (int )fgets($fp);
fclose($fp);
// increment the number of visitors
$hits++;
// open the file and write how many visitors are now
$fp = fopen($visits,"w");
fputs($fp,$hits);
fclose($fp);
?>


could be done with a single fopen/fclose but how is now you can see more clear how to do each step.

regards

IFeelYourPain
07-18-2008, 07:34 AM
Didn't work dude. I think you forgot an echo, but not sure?

oesxyl
07-18-2008, 07:39 AM
Didn't work dude. I think you forgot an echo, but not sure?
it work dude. and you don't need any echo. this do exactly what your previous code indend to do.

showing the number of visitors in your page is another problem, isn't it? for that just echo $hits where you want.

regards

IFeelYourPain
07-18-2008, 07:50 AM
it work dude. and you don't need any echo. this do exactly what your previous code indend to do.

showing the number of visitors in your page is another problem, isn't it? for that just echo $hits where you want.

regards
I tried the exact script you posted up there and nothing happened.

oesxyl
07-18-2008, 08:04 AM
I tried the exact script you posted up there and nothing happened.
post a link to the page.

regards

IFeelYourPain
08-22-2008, 05:43 PM
post a link to the page.

regards
Your script did not work at all. I tried it in a regular php page on my server. I found another script and will see how it works out.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum