You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Jim Maul <jm...@elih.org> on 2004/07/01 19:25:30 UTC

[users@httpd] custom apache logs

I have read through the custom logs section of the apache documentation but i
have been unable to determine if what i want to do is possible.

When using PHP auth with apache _SERVER['PHP_AUTH_USER'] used to get logged to
apache's access log.  We have since switched to authenticating through a form
and then using php sessions and have gotten rid of all instances of
PHP_AUTH_USER.  Because of this, the currently logged in user is no longer
logged to the apache access log.  Is there any way to have PHP variables
recorded in the apache access log?  The currently logged in user is stored in
_SESSION['UserName'].  Can i somehow write this to apache's log?

Any help is appreciated greatly.

Thanks,

Jim

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] custom apache logs

Posted by Jim Maul <jm...@elih.org>.
Quoting Joshua Slive <js...@gmail.com>:

> On Thu,  1 Jul 2004 13:25:30 -0400, Jim Maul <jm...@elih.org> wrote:
>>
>> I have read through the custom logs section of the apache 
>> documentation but i
>> have been unable to determine if what i want to do is possible.
>>
>> When using PHP auth with apache _SERVER['PHP_AUTH_USER'] used to get 
>> logged to
>> apache's access log.  We have since switched to authenticating 
>> through a form
>> and then using php sessions and have gotten rid of all instances of
>> PHP_AUTH_USER.  Because of this, the currently logged in user is no longer
>> logged to the apache access log.  Is there any way to have PHP variables
>> recorded in the apache access log?  The currently logged in user is 
>> stored in
>> _SESSION['UserName'].  Can i somehow write this to apache's log?
>
> There are probably lots of different ways to do this.  The goal is to
> get it into a variable that apache can log.  This could be a response
> header, env variable, an apache "note", etc.
>
> The last one seems the cleanest.  You can use the php apache_note
> function to drop the username into a note using something like
> apache_note("phpauth",_SESSION["UserName"]), and then use %{phpauth}n
> in your logformat to put it in the logs.
>
>

Thanks to everyone who answered this.  I ended up using the "note" idea and it
works great.

Thanks again!

Jim

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] custom apache logs

Posted by Joshua Slive <js...@gmail.com>.
On Thu,  1 Jul 2004 13:25:30 -0400, Jim Maul <jm...@elih.org> wrote:
> 
> I have read through the custom logs section of the apache documentation but i
> have been unable to determine if what i want to do is possible.
> 
> When using PHP auth with apache _SERVER['PHP_AUTH_USER'] used to get logged to
> apache's access log.  We have since switched to authenticating through a form
> and then using php sessions and have gotten rid of all instances of
> PHP_AUTH_USER.  Because of this, the currently logged in user is no longer
> logged to the apache access log.  Is there any way to have PHP variables
> recorded in the apache access log?  The currently logged in user is stored in
> _SESSION['UserName'].  Can i somehow write this to apache's log?

There are probably lots of different ways to do this.  The goal is to
get it into a variable that apache can log.  This could be a response
header, env variable, an apache "note", etc.

The last one seems the cleanest.  You can use the php apache_note
function to drop the username into a note using something like
apache_note("phpauth",_SESSION["UserName"]), and then use %{phpauth}n
in your logformat to put it in the logs.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] custom apache logs

Posted by Tim Burden <ti...@burden.ca>.
This is probably not useful if you need the information in standard
access_log format (for stats tools or whatever), but have you looked into
PHP's error_log() function?
http://www.php.net/manual/en/function.error-log.php

Alternatively you might try replacing %u with \"%{UserName}C\" in your
custom log directive

http://httpd.apache.org/docs-2.0/mod/mod_log_config.html#formats

Also look into PHP's putenv()
http://www.php.net/manual/en/function.putenv.php

I've never tried this, but you might be able to just go ahead and change the
PHP_AUTH_USER variable without actually using it for anything (except
logging).

----- Original Message ----- 
From: "Jim Maul" <jm...@elih.org>
To: "Apache Mailing List" <us...@httpd.apache.org>
Sent: Thursday, July 01, 2004 1:25 PM
Subject: [users@httpd] custom apache logs


> I have read through the custom logs section of the apache documentation
but i
> have been unable to determine if what i want to do is possible.
>
> When using PHP auth with apache _SERVER['PHP_AUTH_USER'] used to get
logged to
> apache's access log.  We have since switched to authenticating through a
form
> and then using php sessions and have gotten rid of all instances of
> PHP_AUTH_USER.  Because of this, the currently logged in user is no longer
> logged to the apache access log.  Is there any way to have PHP variables
> recorded in the apache access log?  The currently logged in user is stored
in
> _SESSION['UserName'].  Can i somehow write this to apache's log?
>
> Any help is appreciated greatly.
>
> Thanks,
>
> Jim
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org