如何在PHP中创建我的网站的日志文件?

6
我想知道如何在PHP中创建我的网站的日志文件?这可以帮助我维护有关每个用户访问的页面和他们在我的网站上执行的所有操作的数据。所以,有没有人能帮助我?
谢谢,

你需要在日志中注册什么? - Paulo H.
你想要存储什么信息?每个用户访问的页面,一般的操作...请更明确! - user898741
1个回答

26
$file = 'people.log';
// The new person to add to the file
$person = "John Smith\n";
// Write the contents to the file, 
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at the same time
file_put_contents($file, $person, FILE_APPEND | LOCK_EX);

请参考手册页面:file_put_contents()


1
感谢您改进这个答案,我已经取消了我的负评。 - Treffynnon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接