
| | |||||||
| Website Development HTML, traffic, hosting, and more... this is the forum for every webmaster. |
Register Now for FREE! | |||||
| |

| | LinkBack | Thread Tools | Display Modes |
| ||||
| 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> On my index page I have: Code: <?php
include("scripts/count.php");
?> 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 |
| Sponsored Links | ||
| |
| |||
| Change the file location to. Code: $COUNTER_FILE = getcwd()."/scripts/hitcounter.dat"; 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 |
| ||||
| 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 |
| ||||
| 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. |
| ||||
| Ah, its okay, I sorted it 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 |