PHP 记录完整请求

3 php logging request

是否可以使用 PHP 记录请求?我还想记录图像、js、CSS 文件请求。

<img src="foo.png">
<link rel="stylesheet" href="foo.css">
Run Code Online (Sandbox Code Playgroud)

我目前使用这段代码,但它只给我当前的请求 uri,而不是其他文件等。我还将所有请求重写到我的 index.php,其中有这行代码。

file_put_contents('foo.txt', $_SERVER['REQUEST_URI'] . PHP_EOL, FILE_APPEND | LOCK_EX);
Run Code Online (Sandbox Code Playgroud)

小智 6

这是将所有 http 请求绘制到文件的选项。这适用于通过 HTTP 协议传输的所有请求

$myFile = "requestslog.txt";
    $fh = fopen($myFile, 'a') or die("can't open file");
    fwrite($fh, "\n\n--------------------------------------
        -------------------------\n");
    foreach($_SERVER as $h=>$v)
        if(ereg('HTTP_(.+)',$h,$hp))
            fwrite($fh, "$h = $v\n");
    fwrite($fh, "\r\n");
    fwrite($fh, file_get_contents('php://input'));
    fclose($fh);
    echo "<html><head /><body><iframe src=\"$myFile\" 
        style=\"height:100%; width:100%;\"></iframe></body></html>"
Run Code Online (Sandbox Code Playgroud)