使用 PHP 将用户名放在 apache access_log 中,不使用 HTTP 身份验证 [英] Put username in apache access_log with PHP and without HTTP auth

查看:21
本文介绍了使用 PHP 将用户名放在 apache access_log 中,不使用 HTTP 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Apache 日志配置中,可以指定应记录 HTTP 身份验证用户名.大多数 PHP 脚本都有自己的、基于 cookie 的身份验证.是否可以在 PHP 中为 Apache 提供用于日志记录的 HTTP 身份验证用户名,即使身份验证是基于 cookie 的?如果是,代码会是什么样子?如果没有,有什么替代方案?

In the Apache log configuration it is possible to specify that the HTTP auth user name should be logged. Most PHP scripts have their own, cookie-based authentication. Is it possible in PHP to provide Apache with a HTTP auth username for logging purposes, even if the authentication is cookie-based? If yes, how would the code look like? If not, what are alternatives?

推荐答案

Apache 在notes 中的模块之间传递数据.如果您将 PHP 作为 Apache 模块运行,则可以使用 apache_note() 来获取和设置注释.然后,您可以包含 %{note_name}n 日志格式字符串 将其写入访问日志.这不会将任何数据泄漏"回客户端.

Apache passes data between modules in notes. If you run PHP as an Apache module, you can use apache_note() to get and set notes. You can then include the %{note_name}n log format string to write this to the access log. This will not "leak" any data back to the client.

在 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 将用户名放在 apache access_log 中,不使用 HTTP 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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