在 Apache 日志配置中,可以指定应记录 HTTP 身份验证用户名。大多数 PHP 脚本都有自己的基于 cookie 的身份验证。即使身份验证是基于 cookie 的,PHP 中是否可以为 Apache 提供 HTTP 身份验证用户名以进行日志记录?如果是,代码会是什么样子?如果不是,有哪些替代方案?
最佳答案
Apache 在注释 中的模块之间传递数据。如果将 PHP 作为 Apache 模块运行,则可以使用 apache_note()
获取和设置笔记。然后您可以包括 the %{note_name}n
log format string将其写入访问日志。这不会将任何数据“泄漏”回客户端。
在 PHP 中:
apache_note( 'username', $username );
在您的服务器配置中:
LogFormat "%h %l %{username}n %t \"%r\" %>s %b" common_with_php_username
CustomLog logs/access_log common_with_php_username
关于php - 使用 PHP 将用户名放入 apache access_log 且不使用 HTTP 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3389169/