Put username in apache access_log with PHP and without HTTP auth

Viewed 9662

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?

5 Answers

I second "towr" answer about

header('X-Username: '.$username);

I though would add what made my configuration work.

  1. The headers apache module is required (if not enabled it would raise an error)
  2. The apache statements needed the always option
CustomLog logs/vhost-access_log logfmtname

# copy response-header value to note
Header always note X-Username username
# unset response-header so client won't get it
Header always unset X-Username
Related