tags:

views:

41

answers:

3

In mod_perl i can do something like:

$r->user("username");

And then the username will show up in the username section in the logs.

Is there a way to do this in php? without having to modify apache?

Edit: So far i've tried both:

$_SERVER['REMOTE_USER'] = "username";
$_SERVER['PHP_AUTH_USER'] = "username";
apache_setenv('REMOTE_USER', "username")

with no luck

Edit2: Apache logs are in the format of:

ipAddress REMOTE_USER IDENT datetime... etc

I'm trying to set REMOTE_USER without using apache's mod_auth, but php code.

A: 

I imagine you could simply override/provide the variable by setting the required super-global as you would any other variable. However that being said, a quick peak at the PHP docs and the variable you speak of isn't listed:

http://www.php.net/manual/en/reserved.variables.server.php

Cheers, Alex

Sorry, see my update. I've already tried the two most obvious (to me) $_SERVER items.
halkeye
A: 

This looks like a likely option: apache_setenv()

Frank Farmer
Very cool, I did not know about that one, but unfortunately it did not work.
halkeye
A: 

The trick is to use apache_setenv() along with changing your log_format to include %{REMOTE_USER}e

So you're basically passing the remote user as an environment variable, and grabbing that value in the log_format. As far as I know there's no way to override the 'original' variable.

Evert