How to disable apending of "referer" to error_log in PHP?
Asked Answered
G

1

7

PHP error logs typically look something like this:

[Tue Sep 02 15:46:13 2014] [error] [client 192.168.0.105] blah, blah, ... , referer: https://192.168.0.21/blah/blah
[Tue Sep 02 15:46:13 2014] [error] [client 192.168.0.105] blah, blee, ... , referer: https://192.168.0.21/blah/blee

How can I get them to look like this?

[Tue Sep 02 15:46:13 2014] [error] [client 192.168.0.105] blah, blah, ... 
[Tue Sep 02 15:46:13 2014] [error] [client 192.168.0.105] blah, blee, ... 

I tried $_SERVER['HTTP_REFERER']=''; but it (not surprisingly) didn't help.

Goolsby answered 2/9, 2014 at 20:49 Comment(3)
In some circumstances we generate an extensive set of diagnostics to the log and EVERY line doesn't need to know the referer.Goolsby
seems more work removing than ignoring - yup i'm no help at all ;)Phalanger
This is an Apache log, right?Installment
P
6

(replying to an old question, I know, but I had to figure this out on my own recently, so maybe this will help somebody else...)

This can be done by setting the 'ErrorLogFormat' directive, either in your server config or virtualhost .conf file. Like this:

ErrorLogFormat "[%t] [%l] [pid %P] %F: %E: [client %a] %M"

Or maybe look up the default in your server config and modify that - you just need to get rid of %{Referer}i, which is what adds the referer url.

Perfidy answered 21/4, 2015 at 12:51 Comment(5)
My problem is not how to permanently disable the referer (I know how to do that), but to conditionally remove it from PHP, NOT from .conf.Goolsby
Huh, sorry, I think I'm not getting what precisely are you asking about, then. Do you need to do this from inside PHP (because you don't have access to the .conf, for example)? Or do you need just the PHP error logs without the referer, while the rest of them have it?Perfidy
I want control from within PHP of whether or not the referrer is appended to the log, on a message by message basis.Goolsby
I don't think that's possible. PHP doesn't have access to the original referer variable nor the logging format used. The only thing I can imagine is somehow throwing the errors with low severity, and then setting the server to log the referer only for messages with a higher severity. I'm not sure if that's even possible, and I suspect it's just not worth the trouble, tbh.Perfidy
This is not working for me. Syntax error on line 84 of /opt/local/apache2/conf/extra/httpd-ssl-email.conf: Invalid command 'ErrorLogFormat', perhaps misspelled or defined by a module not included in the server configurationInstallment

© 2022 - 2024 — McMap. All rights reserved.