I’m creating a custom log file and am looking for help on applying two options. I’m not applying both options together I’m just trying to get an understanding of how to apply the different options where I would be able to apply it in different situations. The php is as follows :
[php]
// Log IP Address Of All Visitors
$filename = $_SERVER[‘DOCUMENT_ROOT’] ."/Logs/IP_log(1).txt";
$handle = fopen($filename, “a”);
$content = "[ " . date( ‘M d, Y, g:i a’ ) . " ] - " . $_SERVER[‘REMOTE_ADDR’];
fwrite($handle, $content . “\n”);
fclose($handle);
$max_size = 500000;
if (filesize($filename) >= $max_size)) {
// Apply either option 1 or option 2
}
[/php]
The first option I’ve been attempting to use and have been failing at is the option to erase the content within, bringing the file size back to zero. The other option I’ve yet to attempt is once file size reaches max size is to create a new file with same name just apply the number change as follows :
IP_log(1).txt // The file that already exist
IP_log(2).txt
IP_log(3).txt
and so on.
On any attempts with the if statement I’ve been getting errors. I always try many different things before I post here on this site so I have made many attempts. The error is traced back to the if statement. Thanks to all who help give any assistance on either option. The option I would really like to learn most is to create a new file when file size is reached. Once again many thanks in advance for all who help with my learning php, I’m always appreciative.