Computer Forums

Go Back   Computer Forums > Internet > Website Development

Website Development HTML, traffic, hosting, and more... this is the forum for every webmaster.

Register Now for FREE!
Computer Forums

Username: Password: Confirm Password: E-Mail: Confirm E-Mail:
Agree to forum rules 


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-11-2008, 11:44 AM
Jam's Avatar
Jam Jam is offline
CompuForums Moderator
 
Join Date: 02 Mar 2008
Location: In My Own Little World
Posts: 624
Jam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond repute
Default PHP Hit Counter Problem

So I have this code for a simple hit counter:

Code:
<?php 
 
$COUNT_FILE = "hitcounter.dat"; 
 
if (file_exists($COUNT_FILE)) { 
    $fp = fopen("$COUNT_FILE", "r+"); 
    flock($fp, 1); 
    $count = fgets($fp, 4096); 
    $count += 1;  
    fseek($fp,0); 
    fputs($fp, $count); 
    flock($fp, 3); 
    fclose($fp); 
} else { 
    echo "Error - Cannot find file"; 
} 
 
?> 
<center>This page has been viewed <b><?php echo $count; ?></b> times<br></center>
This file is in a directory with the file hitcounter.dat, which contains the number 0.

On my index page I have:

Code:
       <?php 
    include("scripts/count.php"); 
       ?>
So all the files are in the right places, and named corectaly, but It keeps returning the 'Error - Cannot find file' message.

Can anyone spot an error in the code or anythign?

thanks in advice!

Jam
__________________
Become a Premium Member today!
- Advert Free - Increased PM Storage - 1,000,000 C$ - Increased Avatar Size - Access To Premium Members Forum - Colored Username -
_______________________________________
Anyone who isn't confused here doesn't
really understand what's
going on


JamsUbuntu.blogspot.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-14-2008, 03:28 AM
Newbie
 
Join Date: 09 Aug 2008
Posts: 2
elchupathingy is on a distinguished road
Default Re: PHP Hit Counter Problem

Change the file location to.
Code:
$COUNTER_FILE = getcwd()."/scripts/hitcounter.dat";
That should work.

also you don't need to read that many bytes from the file, do like 128 or something. I highly doubt you will get that many hits

Also the reason for the error is that you including the file into your index this means that the current dir is not right, so you need to add the dir to the file including the scripts folder. What your script is doing is trying to open a file in the dir that you index file is in and not the dir the counter fil is in.

enjoy, ELchupathingy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-27-2008, 02:31 PM
Jam's Avatar
Jam Jam is offline
CompuForums Moderator
 
Join Date: 02 Mar 2008
Location: In My Own Little World
Posts: 624
Jam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond repute
Default Re: PHP Hit Counter Problem

Hey,
Thanks for replying. Sorry I didn't respond earlier..

So now it says 'This page has been viewed times'

So I'm kinda getting there, but there seems to be a problem with reading the hitcounter.dat file? I have no idea.. :S

Thanks,
Jam
__________________
Become a Premium Member today!
- Advert Free - Increased PM Storage - 1,000,000 C$ - Increased Avatar Size - Access To Premium Members Forum - Colored Username -
_______________________________________
Anyone who isn't confused here doesn't
really understand what's
going on


JamsUbuntu.blogspot.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-27-2008, 02:40 PM
Ash's Avatar
Ash Ash is online now
CF owner
 
Join Date: 27 Jul 2005
Location: Devon, UK
Posts: 4,130
Ash has a reputation beyond reputeAsh has a reputation beyond reputeAsh has a reputation beyond reputeAsh has a reputation beyond reputeAsh has a reputation beyond reputeAsh has a reputation beyond reputeAsh has a reputation beyond reputeAsh has a reputation beyond reputeAsh has a reputation beyond reputeAsh has a reputation beyond reputeAsh has a reputation beyond repute
Default Re: PHP Hit Counter Problem

Have you checked the permissions of the file? It needs to be readable/writable by the webserver user.
__________________
Thanks,
Ash
CF Founder

Great Webhosting. Shared starting at $2 per month. VPSes starting at $6 per month.
www.Centicero.com

Want to get in touch? Send me a PM | Do you want to continue receiving free help? Or do you want this site to close? Become a premium member.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-27-2008, 02:46 PM
Jam's Avatar
Jam Jam is offline
CompuForums Moderator
 
Join Date: 02 Mar 2008
Location: In My Own Little World
Posts: 624
Jam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond reputeJam has a reputation beyond repute
Default Re: PHP Hit Counter Problem

Ah, its okay, I sorted it I had an extra '.' in a place it shouldn't of been
but yeah, thanks anyways Ash

Jam
__________________
Become a Premium Member today!
- Advert Free - Increased PM Storage - 1,000,000 C$ - Increased Avatar Size - Access To Premium Members Forum - Colored Username -
_______________________________________
Anyone who isn't confused here doesn't
really understand what's
going on


JamsUbuntu.blogspot.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
counter, hit, php

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:21 AM.



Powered by: vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Content © Copyright 2005-2008 CompuForums. All Rights Reserved. Some content © Copyright of the respective owners.
Cheap Electricity - Credit Counseling - Mobile Phone - Credit Card Consolidation

Content Relevant URLs by vBSEO 3.2.0 RC5