是否可以使用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);
答案 0 :(得分:1)
是的,确实如此。您可以通过php脚本传递所有请求,以便您可以记录操作。例如,像http://url.com/img.jpg
这样的简单图像请求将变为http://url.com/index.php?action=download&file=img.jpg
,脚本将处理日志记录,文件下载和正确的标题。
另外考虑到您的http服务器可能已经记录了请求,如果您正在使用它,请查看apache的access_log。
答案 1 :(得分: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>"
答案 2 :(得分: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 - 如果需要,您可以在此处设置完整的文件路径。
希望这会对你有帮助!