Jump to content

[SOLVED] Counter problem


Jest

Recommended Posts

I'm having a problem with my counter.  I found this as a tutorial.

<?php
$count = ("counter.txt");
//now this is where we open the file
$visits = file($count);
//this adds 1 hit
$visits[0]++;
//Now open the counter
$fp = fopen($count , "w");
//put the new count value into the txt file
fputs($fp , "$visits[0]");
//close the file
fclose($fp);
?>

I set the text file at 200, but it doesn't increment.  Could it be because I have this counter twice on my site?  It is included once when someone fills out a form, and again when another form is filled out to find the total number of 'sign-ups'.

Link to comment
Share on other sites

Are you using the same text file for both to?

 

Yes.

 

...

 

Hmm, well I asked that because it seems to work just fine for me.

Perhaps instead of using a file, use a database to store it?

 

I'd rather not have to learn how to read/write from a database.  Unless there is some tutorial or something.

 

...

 

 

Is the file in the same directory as the counter.txt?

 

Yes.

Link to comment
Share on other sites

If you plan on ever doing anything serious, you'll need to learn how to use a database.

 

Add this to the top of the file

ini_set('display_errors', 1);

error_reporting(E_ALL);

 

Any errors?

 

I'll learn databases if I have to, I'm not going to school for web though.  There were no errors.  I opened counter.txt though and it was blank.  When I was displaying the counter the line "echo $visits[0];" was after "fclose($fp);".  It looks like its working now, I guess that was the problem.  Thanks everybody.

Link to comment
Share on other sites

On a quick note:

It doesn't matter if you are going to school for it or not.

What matters is whether you are just using it to play temporarily or if you want to get serious with it.

 

If you ever do decide to get serious, Jesirose is dead on when she says you will need to learn databases.

 

Good luck :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.