如何记录与PHP和MySQL用户操作? [英] How to log user actions with php and mysql?

查看:321
本文介绍了如何记录与PHP和MySQL用户操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作我的CMS,我希望它被用户和其他管理员登录活动。 例如:当新用户注册和管理,使一个新的消息后 - >更新上次活动

I'm working on my CMS and I want it to log activities by users and other admins. For example: when new user registers or admin makes a new news post -> update last activity.

我想知道什么是最好的,最简单的方法。

I want to know what is the best and easiest way.

推荐答案

  • 在数据库中创建一个表 记录你的用户活动。
  • 定义的各种活动类型 可以在您的应用程序发生。
  • 创建,记录一个共同的功能 任何活动,以该表。
  • 在调用该函数从任何地方 在执行日志,值得活动 你的应用程序。

  • Create a table in your database to log your user activity.
  • Define the various activity types that can happen in your App.
  • Create a common function that logs any activity to that table.
  • Call that function from anywhere you perform log-worthy activities in your app.
  • 您可以然后写一个报告工具,让您的管理员访问这些记录的活动,您可以过滤用户,时间和活动类型。

    You can then write a reporting tool that gives your admins access to those logged activities, you can filter by user, time and activity types.

    在我的日志框架,我专门标志,它可以被看作是恶意行为的活动,并为它们分配不同的数字的威胁值。如果一个用户的线程值的总和达到某一阈值予注销用户

    In my log-framework, I specially mark activities which could be seen as malicious actions and assign them different numeric threat-values. If the sum of a user's thread-value reaches a certain threshold I log-out the user.

    在理想情况下,如果你写一个应用程序,你写你的基础设施code一样,在开始记录,然后用它在所有的业务逻辑,code后。

    Ideally if you write an Application, you write your infrastructure code like logging at the very beginning and then use it in all your business logic code later.

    修改的清理:

    随着时间的推移,你可能会收集大量的该表中的记录。根据您的要求,你可以做不同的事情。

    Over time you may collect lots of records in that table. Depending on your requirements you could do different things.

    • 删除超过X天的任何条目(也许一年)

    • Delete any entries older than x days (maybe a year)

    删除某些类型超过X天的任何条目,但保留其他类型的条目较长,或者永远。

    Delete any entries of certain types older than x days, but keep entries of other types for longer, or forever.

    移动超过一定的阈值到一个归档日志表项。这样可以使你的主表小,但可以访问旧的日志数据,如果你真的不得不这样做。我对我的审查日志页面复选框使用存档

    Move entries older than a certain threshold into an archive log table. This keeps your main table small but allows you to access older log data if you really have to. I have a checkbox Use archive on my review logs page.

    这篇关于如何记录与PHP和MySQL用户操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆