Jest Posted February 24, 2007 Share Posted February 24, 2007 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'. Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted February 24, 2007 Share Posted February 24, 2007 You check your file permissions on the file to be sure your script can write to it? Quote Link to comment Share on other sites More sharing options...
Jest Posted February 24, 2007 Author Share Posted February 24, 2007 Yeah, counter.txt is CHMOD 777 Quote Link to comment Share on other sites More sharing options...
DeathStar Posted February 24, 2007 Share Posted February 24, 2007 Are you using the same text file for both to? Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted February 24, 2007 Share Posted February 24, 2007 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? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2007 Share Posted February 24, 2007 Is the file in the same directory as the counter.txt? Quote Link to comment Share on other sites More sharing options...
Jest Posted February 24, 2007 Author Share Posted February 24, 2007 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 24, 2007 Share Posted February 24, 2007 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? Quote Link to comment Share on other sites More sharing options...
Jest Posted February 24, 2007 Author Share Posted February 24, 2007 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. Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted February 24, 2007 Share Posted February 24, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.