php geeks,专业人士和所有其他人如何记录他们的平面文件.
是否有可以记录一个.php页面的功能?
可以控制php中的日志记录吗?
另外,有人用这个来记录吗?[ http://www.monperrus.net/martin/phpmodlog][1]
显然我的第一个问题不明确......
您可以创建一个fwrite用于将事件写入日志文件的函数.
例如:
function logEvent($message) {
if ($message != '') {
// Add a timestamp to the start of the $message
$message = date("Y/m/d H:i:s").': '.$message;
$fp = fopen('/path/to/log.txt', 'a');
fwrite($fp, $message."\n");
fclose($fp);
}
}
Run Code Online (Sandbox Code Playgroud)
您还应该添加文件可写的检查,您可以在fwrite页面上找到该代码.
对于您提到的每个事件,您可以执行以下操作:
// Log that user has started playing
logEvent('User '.$user.' has started playing Battleships.');
Run Code Online (Sandbox Code Playgroud)
将其展开以包含/执行您想要的任何操作.
编辑:您已编辑过您的问题,但我会在此留下答案,因为您可能会发现它很有用.正如其他人所提到的那样,当某人关闭浏览器窗口时,你真的无法确定.也改为追加而不是覆盖.
| 归档时间: |
|
| 查看次数: |
2699 次 |
| 最近记录: |