简体   繁体   中英

PHP Activity log

So, I have a web app based on PHP and a DB based on MySQL. The app registers employees (table name: colaboradores) and items (Table name: ativos) (like computers and stuff like that) and then on the app it has the users table (that basically is for permissions like create and delete records).

The point is, I want every action performed by any user to be registered on a log file (I was thinking on creating a new table on the BD called log maybe? ) and show a text field on the page of every item that is register all the life's cycle of that item (For exemple, register on the log that the user mike added an Iphone to the employee Sam today). Any tips of how can I do that?

you can just use a log file system its more speedy than database to store the user activity(insert,update,delete) :

$file=fopen('activity.log','a');

// in insert condition
if($inser)
{
    fwrite($file,$user->name.' : insert'."\n");


}
// in update condition
if($update)
{
    fwrite($file,$user->name.' : update'."\n");


}
// in delete condition
if($delete)
{
    fwrite($file,$user->name.' : delete'."\n");


}

fclose($file);

Here is a function for writing to a specified log directory. You just pass in the log message and it creates/updates a log file named after the current date. Be sure to give nginx/apache ownership of the log directory with chown .

function logActivity($data) {
    file_put_contents("/home/logs/" . date("m-d-Y"), date("h:i a") . ": " . $data . "\n", FILE_APPEND | LOCK_EX);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM