PHP counter acting weired!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
akjackson1
Forum Newbie
Posts: 18
Joined: Mon Apr 14, 2008 9:08 am

PHP counter acting weired!

Post 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!
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: PHP counter acting weired!

Post by WebbieDave »

User avatar
akjackson1
Forum Newbie
Posts: 18
Joined: Mon Apr 14, 2008 9:08 am

Re: PHP counter acting weird!

Post 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...
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP counter acting weird!

Post 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");
User avatar
akjackson1
Forum Newbie
Posts: 18
Joined: Mon Apr 14, 2008 9:08 am

Re: PHP counter acting weired!

Post 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!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP counter acting weired!

Post 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.
Post Reply