3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

POSTリクエストの内容をアクセスログに出力する方法

Posted at

httpd.conf

%r の代わりにレスポンスヘッダを使ってログファイルに値を渡す

LogFormat "(前略) \"%{X-MYQUERYSTRING}o\" (後略)" post_logformat
SetEnvIf Request_Method "POST" method_is_post
CustomLog "|/usr/local/apache/bin/rotatelogs post_log.%y%m%d 86400 540" post_logformat env=method_is_post

CGI側でレスポンスヘッダを1つ追加する

if($ENV{REQUEST_METHOD} eq 'POST'){
	%vars = $cgi->Vars;
	$qs = join('&', map{ join('=', $_, $vars{$_}) } keys %vars);
	print 'X-MYQUERYSTRING: '.'POST '.$ENV{REQUEST_URI}.'?'.$qs.' '.$ENV{SERVER_PROTOCOL}."\n";
}

エスケープは必要だと思う

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?