php日志完成请求

问题描述 投票:1回答:3

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

<img src="foo.png">
<link rel="stylesheet" href="foo.css">

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

file_put_contents('foo.txt', $_SERVER['REQUEST_URI'] . PHP_EOL, FILE_APPEND | LOCK_EX);
php logging request
3个回答
1
投票

是的。您可以通过php脚本传递所有请求,以便您可以记录操作。例如,像http://url.com/img.jpg这样的简单图像请求将成为http://url.com/index.php?action=download&file=img.jpg,脚本将处理日志记录,文件下载和正确的标题。

还要考虑到您的http服务器可能已经记录了请求,如果您正在使用它,请查看apache的access_log


0
投票

以下是将所有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>"

0
投票
// Reports all errors
error_reporting(E_ALL);
// Do not display errors for the end-users (security issue)
ini_set('display_errors','Off');
// Set a logging file
ini_set('error_log','request_log_file.log');

注意 - request_log_file.log - 如果需要,您可以在此处设置完整文件路径。

希望对你有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.