Skip to Content
Frontlane Studio
All Snippets
PHP Security November 14, 2024

Log HTTP Request Headers for Security Audit

A PHP snippet for Log HTTP Request Headers for Security Audit.

WordPress PHP

A PHP snippet for Log HTTP Request Headers for Security Audit.

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' );