Page 1 of 1

PHP counter acting weired!

Posted: Thu Jun 19, 2008 2:36 pm
by akjackson1
Hi,
I have a simple php script that is suppose to write the number of page loads into a txt file, it works fine, but it doesn't right ANYTHING into the txt file, it just keeps counting away even when there's no txt file on the server!!

Here is the code I am currently using:

Code: Select all

<?
$counter_file = ("hits.txt");
$visits = file($counter_file);
$visits[0]++;
 
$fp = fopen($counter_file , "w");
fputs($fp , "$visits[0]");
 
fclose($fp); 
 
print $visits[0];
?>
You can see the counter in action down the bottom of this page, next to the audio player: http://s244087696.onlinehome.us/hillsviewtrio/
And there is currently NO txt file!

Re: PHP counter acting weired!

Posted: Thu Jun 19, 2008 2:46 pm
by WebbieDave

Re: PHP counter acting weird!

Posted: Thu Jun 19, 2008 2:54 pm
by akjackson1
Haha! that's weird, it was suppost to be in a counter folder, Thanks for you help :D

Any ideas on the design? It's a site i'm making for some friends...

Re: PHP counter acting weird!

Posted: Thu Jun 19, 2008 7:33 pm
by califdon
akjackson1 wrote:Haha! that's weird, it was suppost to be in a counter folder
What's weird about it? You specified it as being in the same folder:

Code: Select all

$counter_file = ("hits.txt");

Re: PHP counter acting weired!

Posted: Thu Jun 19, 2008 9:35 pm
by akjackson1
Sorry, I kinda figured it out later, it was for some reason putting it in the main directory, I'm still a little confused, but it works!

Re: PHP counter acting weired!

Posted: Thu Jun 19, 2008 9:58 pm
by califdon
akjackson1 wrote:Sorry, I kinda figured it out later, it was for some reason putting it in the main directory, I'm still a little confused, but it works!
When you don't supply any path, the default is the same directory where the script file is. If you want it someplace else, you have to tell it where you want it.