Page 1 of 1

GraphCount - automatic log file creation

Posted: Sun Jan 20, 2008 7:29 am
by GL700Wing
/*************************************
Title: GraphCount log file automatic creation
Version: 1.0
Author: Kathy Leslie
Demo: www.goldwing.org.au

Description:
Inserted the following code in graphcount.php to automatically create the text log file if it doesn't exist so that a counter is always displayed.

*************************************/

Insert the following code before the "if (file_exists($logfile)) {" line - should be about line 57

/* Create the log if it doesn't exist */
if (!file_exists($logfile)) {
$fp = fopen($logfile, "w") or die('ERROR: Can\'t write to the log file ('.$logfile.'), please make sure this file exists and is CHMOD to 666 (rw-rw-rw-)!');
$count = 0;
flock($fp, LOCK_EX);
fputs($fp, $count);
flock($fp, LOCK_UN);
fclose($fp);
chmod($logfile, 0666);
}

Posted: Sun Jan 20, 2008 12:55 pm
by Klemen
This was included in counter version 1.0 but I decided to remove it in 1.1 as it could lead to potential security issues.

Posted: Sun Jan 20, 2008 9:07 pm
by GL700Wing
Hi Klemen,

Thanks for your reply. Hopefully I won't experience any security problems with this modification as none of the directories or sub-directories for the Graphic Counter are world writable.

My main reasons for adding this code were:
1. so that the webmaster (usually me but sometimes another person) does not have to remember to create the log file when a new page is created; and
2. as a way of zeroing the counters (be deleting the log files on the server).


Kathy

Posted: Mon Jan 21, 2008 8:20 pm
by Klemen
Anyway, forgot to say thanks for sharing :wink: