RPeraltaJr
5/31/2017 - 6:52 PM

Create an automatic log file on the server

Create an automatic log file on the server

<?php

date_default_timezone_set("America/New_York");
$file_date = date('Y-m');
$timestamp = date('Y-m-d h:m:s');
$log_file = "_logs/{$file_date}_log";

$log = "\n\n\n";
$log .= "$job_counter jobs from portal $portal added on $timestamp";
$log .= "\n\n";
file_put_contents($log_file, $log, FILE_APPEND);

?>
<?php
  // Logging In Function()
  // ....

  // Something to write to txt log
  $log  = "User: $db_username, logged in on " . date('F j, Y, g:i a') . "\n";
  
  // Save string to log, use FILE_APPEND to append.
  file_put_contents('./log/log_'.date("m-d-Y").'.txt', $log, FILE_APPEND);
?>