4

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.

4
  • Have you done a phpinfo() as an authenticated user? Somewhere in the resulting data, you should find your username... Commented Jun 16, 2010 at 4:07
  • my authenticated user is coming in programmaticly, not from apache. I know how to get the user from apache, i don't know how to tell apache what the user is. Commented Jun 16, 2010 at 4:10
  • I'm confused. Are you or are you not trying to determine the username of the HTTP-authenticated user? If the user isn't HTTP-authenticated, then the things you're trying to do won't work. Can you edit your question to explain the nature of the authentication in more detail? Commented Jun 16, 2010 at 5:01
  • I'm trying to set it to save it to the apache logs. All of the things i've listed thus far is setting, not getting. Updated question. Commented Jun 16, 2010 at 5:20

3 Answers 3

2

This looks like a likely option: apache_setenv()

Sign up to request clarification or add additional context in comments.

1 Comment

Very cool, I did not know about that one, but unfortunately it did not work.
2

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.

Comments

0

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

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.