wordpress-website-lifecycle/debug/debug-access-log.php
Viktor Szépe b66a979fd3
Some checks failed
integrity.yml / Add access log functionality in debug-access-log.php (#71) (push) Failing after 0s
Back-end / Syntax errors (push) Failing after 2s
Docs / Markdown (push) Failing after 2s
Spelling / 文A Typos check (push) Failing after 3s
Add access log functionality in debug-access-log.php (#71)
This PHP script logs access requests in an Apache-like format to an access.log file.
2026-07-23 10:25:39 +02:00

21 lines
654 B
PHP

<?php
/*
* Insert this snippet at the top of wp-config.php
*/
// Write an Apache-like access.log
register_shutdown_function(function () {
file_put_contents(dirname(__DIR__).'/access.log', sprintf(
'%s - - [%s] "%s %s %s" %d %.2f "%s" "%s"' . PHP_EOL,
$_SERVER['REMOTE_ADDR'] ?? '127.0.0.1',
date('d/M/Y:H:i:s O'),
$_SERVER['REQUEST_METHOD'] ?? 'GET',
$_SERVER['REQUEST_URI'] ?? '/',
$_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1',
http_response_code(),
timer_float(),
$_SERVER['HTTP_REFERER'] ?? '-',
$_SERVER['HTTP_USER_AGENT'] ?? '-'
), FILE_APPEND | LOCK_EX);
});