Jump to content

Not quite working.


INeedAGig

Recommended Posts

Alrighty, I have been working on a simple hit counter and I can't quite get it to work, I am having trouble getting the system to actually display the amount of hits, here is the code for review.

 

 

This code below is located within the file I call 'count_processor.php'

<?php $myfile = "counter/hits.txt";
if(file_exists($myfile)) //Check for file
{
$var = fopen('$myfile,\'r+\'');
//opens in read and write mode our file
$visits = fread($var,filesize($myfile));
//puts the content of the file for its whole lenght
rewind( $var );
//resets the file position indicator to the beginning
$visits++; //increments the actual number of vists by 1
fwrite($var, $visits);
//writes in the variable the actual (incremented) value
fclose($var);//closes our file reference
}
else
{
print "File $myfile doesn't exist...";
Die();
//if the file doesn't exist prompts a warning and kills the script
}
$message = sprintf("%s recent visitors",$visits);
//saves our visits message in a variable ($message) that will be used as output
print $message;
?>

 

Now, this small snippet of code is located on the page I want to count hits for, which is the index.php file. This calls upon the above code and in turn renders the data onto the page, but all that is showing up on the index.php page is 'recent visitors' which is the text after the numerical value of visitors is displayed, i.e. "137 recent visitors"

 

<?php include 'counter/count_processor.php'; ?>

 

 

Any ideas? Thanks!

 

Also, you will notice I am using a flat-file system (.txt), no MySQL database.

Link to comment
Share on other sites

Alrighty, I fixed that line of code, which is now:

 

$var = fopen("$myfile", "r+") or exit ("Unable to open file!");

 

But I am receiving this error on the page:

 

Warning: fopen(counter/hits.txt) [function.fopen]: failed to open stream: Permission denied

 

Link to comment
Share on other sites

I already have the file created, with the 0, which has now updated itself to '1' but no further, I can't CHMOD, constant '504 command not implemented for that parameter' error in FileZilla....I know that's what is holding it up...just not sure how to get the permissions set now.

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.