LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-28-2003, 10:33 AM   #1
ukch
LQ Newbie
 
Registered: May 2003
Location: Croydon, UK
Distribution: Ubuntu / LinuxFromScratch
Posts: 19
Blog Entries: 2

Rep: Reputation: 0
php hit counter problems


I have a problem with a php script on my website. Here is the script:

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

This script used to work fine, but as soon as I uploaded it onto my site and reset it to 0 it has not been updating since.

The text file has permissions 666.

Does anyone have ideas?
 
Old 11-28-2003, 11:00 AM   #2
dkaplowitz
Member
 
Registered: Oct 2002
Location: Havertown PA
Distribution: Ubuntu/RHEL/Fedora
Posts: 253

Rep: Reputation: 31
Does the site you uploaded it to have PHP support enabled?

What is the output of the phpinfo() tag on your site?
 
Old 11-28-2003, 11:20 AM   #3
ukch
LQ Newbie
 
Registered: May 2003
Location: Croydon, UK
Distribution: Ubuntu / LinuxFromScratch
Posts: 19

Original Poster
Blog Entries: 2

Rep: Reputation: 0
Yes, the site does have php support. (all the other php scripts work fine)

Also, I forgot to mention, the hit counter doesn't work on my localhost any more either.

I have checked all through the code for bugs, but it is the same as it always was. I can't see any reason why it should stop working...
 
Old 11-28-2003, 04:02 PM   #4
RTT
Member
 
Registered: Nov 2003
Location: England
Distribution: slackware, FreeBSD
Posts: 33

Rep: Reputation: 15
what does $hits[0] echo out as?
 
Old 11-29-2003, 05:48 AM   #5
mymojo
Member
 
Registered: Oct 2003
Distribution: Slackware 9.1
Posts: 176

Rep: Reputation: 30
Try text file permissions 775 or 777
 
Old 11-29-2003, 12:28 PM   #6
ukch
LQ Newbie
 
Registered: May 2003
Location: Croydon, UK
Distribution: Ubuntu / LinuxFromScratch
Posts: 19

Original Poster
Blog Entries: 2

Rep: Reputation: 0
Quote:
Originally posted by RTT
what does $hits[0] echo out as?
$hits[0] echoes 0 (the contents of the txt file)

mymojo: Tried both. I have a feeling it should be 666.
 
Old 11-29-2003, 03:25 PM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Try changing:
$hits[0] ++;
to:
$hits[0]+=1;
 
Old 11-30-2003, 02:10 AM   #8
mymojo
Member
 
Registered: Oct 2003
Distribution: Slackware 9.1
Posts: 176

Rep: Reputation: 30
Try starting off with number of hits as 1 (in hitcount.txt).

Last edited by mymojo; 11-30-2003 at 02:11 AM.
 
Old 11-30-2003, 06:53 AM   #9
ukch
LQ Newbie
 
Registered: May 2003
Location: Croydon, UK
Distribution: Ubuntu / LinuxFromScratch
Posts: 19

Original Poster
Blog Entries: 2

Rep: Reputation: 0
Quote:
Originally posted by david_ross
Try changing:
$hits[0] ++;
to:
$hits[0]+=1;
It worked! Thanks!

I'll click your afro right now!
 
Old 12-03-2003, 03:51 PM   #10
mymojo
Member
 
Registered: Oct 2003
Distribution: Slackware 9.1
Posts: 176

Rep: Reputation: 30
I think it could be $hits[0]++; as well (the space between the ++ and the [0] could have made it fail to work - $hits[0] ++; )
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Counter-Strike php control script JedisonGames Linux - Software 5 02-23-2006 11:31 PM
Counter-strike source : Texture problems svu Linux - Games 4 10-27-2005 12:34 PM
Apache Server and Hit Counter k1ll3r_x Linux - Software 4 07-05-2005 06:58 AM
hit counter dragon Programming 6 07-04-2005 10:06 PM
Radius Counter Problems otisthegbs Linux - Wireless Networking 3 11-09-2004 02:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration