Originally posted by planetsim
No it wont create a new log file each month this is something you have to do code to do. But it will slow down performance even though it states it will go straight to the EOF to append it still has to find the EOF.
If traffic is going to be quite high maybe creating a log for each day however eventually this will become very very big. You may want to create Directory for each month.
Also is there any specific reason to do so, as just using the Ordinary Logs for the server should really suffice.
How would I go about having it create a file, I tried using fopen() but it only gives me errors, and php.net says if the file doesnt exist it will try to create it. But it doesnt. Anyhow, The server logs won't do, because not every user has access to server logs, remember this is going to be distributed to people publically some users won't even know how to check the log files on the server, this is means of logging them in a way the owner of the site can simply view and understand easily. I have it set up to create different folders for each year/month/ and a different file for eacdh day, but how do I have it create the files when they dont exist? That is my question.
<?php
/*******************************************************************
**
** File: log.php
** Description: Records every visitor click, and records detailed
** information such as the day & hour they visited, their IP Addr,
** their username (if logged in), their agent, and actions
**
*******************************************************************/
$Day_Logged = date("d");
$Month_Logged = date("F");
$Year_Logged = date("Y");
$filename = $Current_Directory."/log/".$Year_Logged."/".$Month_Logged."/".$Day_Logged.".log";
$file_content = "DATE: ". $date ." - USER: ".$user->name()." - IP: ".$_SERVER['REMOTE_ADDR']." - AGENT: ".$_SERVER['HTTP_USER_AGENT']." - ACTION: ".$base_url.$_SERVER['REQUEST_URI']."
";
$error_msg = "<strong>The visitor log file must be given writting permissions! Please content the webmaster at ".$Admin_Email." about this issue ASAP!</strong>";
if (!$handle = fopen($filename, "a")) {
die($error_msg);
}else{
if(is_writable($filename)){
if (fwrite($handle, $file_content) === FALSE) {
die($error_msg);
}
fclose($handle);
}else{
die($error_msg);
}
}
?>
there is the code as it stands now..