Write data to text file, create log file in PHP

0
11
PHP

This tutorial explains how to write data to text file in php, you can create log file that stores the access of file by client.

function create_log($error, $msg, $source, $page)
{
$log  = "User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a").PHP_EOL.
        "Attempt: ".$page.PHP_EOL.
        "Error: ".$error.PHP_EOL.
        "Message: ".$msg.PHP_EOL.
        "Source: ".$source.PHP_EOL.
        "-------------------------".PHP_EOL;
//Save string to log, use FILE_APPEND to append.
   
    file_put_contents('/data/log_'.date("j.n.Y").'.txt', $log, FILE_APPEND);
   
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here