<?php

class CspReport
{
    public function process($post)
    {
        $report = json_decode($post);

        if ($report) {
            $report->{'user-agent'} = $_SERVER['HTTP_USER_AGENT'];

            $data = json_encode(
                $report,
                JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
            );

            $this->log($data);
        }
    }

    private function log($data)
    {
        $logfile = dirname(__DIR__) . '/csp-report.log';
        file_put_contents($logfile, $data . "\n", LOCK_EX | FILE_APPEND);
    }
}

<?php

class CspReport
{
    public function process($post)
    {
        $report = json_decode($post);

        if ($report) {
            $report->date = date("Y-m-d H:i:s");

            foreach (getallheaders() as $name => $value) {
                $report->headers[$name] = $value;
            }

            $data = json_encode(
                $report,
                JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
            );

            $this->log($data);
        }
    }

    private function log($data)
    {
        $logfile = dirname(__DIR__) . '/csp-report.log';
        file_put_contents($logfile, $data . "\n", LOCK_EX | FILE_APPEND);
    }
}

Add date and request headers in CSP report log
Add date and request headers in CSP report log
