RE: [PHP] Use PHP to log into Apache logs?
| From: | John Huggins | Date: | Wed, 08 Nov 2000 14:58:17 +0000 |
| Subject: | RE: [PHP] Use PHP to log into Apache logs? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24314@lists.php.net to get a copy of this message | ||
Well for recording the username change your Apache Config LogFormat from:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
\"%{User-Agent}i\""
combined
to:
LogFormat "%h %l %{Login}o %t \"%r\" %>s %b \"%{Referer}i\"
\"%{User-Agent}i\"" combinedlogin
Then use this new log definition in your CustomLog directive.
Then BEFORE ANY OTHER OUTPUT in your PHP script put a header function like
so with the comments if you like:
// For the purposes of the Apache logs, send the username if it exists
from the cookie.
// Apache must be configured to take the Environment variable "Login" for
this to work like so:
// {Login}o in the Custom Log definition. This is here because we must
print headers before
// any other output.
if ( $user_name ) {
Header("Login: $user_name");
}
The $user_name variable comes from a cookie I plant earlier, but could be
any variable.
Restart your Apache and you should not see the user name in the otherwise
unused third field in the log files. Web log analyzers such as
www.webalizer.com correctly interpret this user name field. A "-" will
appear like usual when you do not define this environment variable.
In case you are wondering, this field will get set in Apache's usual log
format when you use the MOD_AUTH stuff.
This works great for me with sites like www.astronomy.net.
John
> -----Original Message-----
> From: Erick Papadakis [mailto:erick_papadakis@yahoo.com]
> Sent: Wednesday, November 08, 2000 8:52 AM
> To: PHP General
> Subject: [PHP] Use PHP to log into Apache logs?
>
>
> How can I use PHP to add some values to the default
> Apache log file? I want to store more information such
> as the user who has logged in, the sessions etc.
> Usually this is done through databases etc
> (profiling?) but I would like to do this in weblogs
> itself?
>
> Any ideas about how I can do this?
>
> Thanks/erick
>
> __________________________________________________
> Do You Yahoo!?
> Thousands of Stores. Millions of Products. All in one Place.
> http://shopping.yahoo.com/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>