Log HTTP Request Headers for Security Audit

Last updated 1 month ago

PHP
function my_plugin_log_http_headers() {
    if ( is_admin() ) {
        $headers = getallheaders();
        $log_file = ABSPATH . 'wp-content/plugins/my-plugin-http-headers.log';
        $log_entry = date( 'Y-m-d H:i:s' ) . " - Request Headers: \n" . print_r( $headers, true ) . "\n\n";

        file_put_contents( $log_file, $log_entry, FILE_APPEND );
    }
}
add_action( 'wp_loaded', 'my_plugin_log_http_headers' );

All code snippets are licensed GPLv2 or later unless otherwise stated.