Skip to content

Instantly share code, notes, and snippets.

@kawahara
Created November 1, 2014 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kawahara/f5de6c39e69c4b86b3fd to your computer and use it in GitHub Desktop.
Save kawahara/f5de6c39e69c4b86b3fd to your computer and use it in GitHub Desktop.
<?php
$fp = fopen(__DIR__.'/logs/access.log', 'a');
$headers = [];
foreach($_SERVER as $name => $value) {
if (preg_match('/^HTTP_.*/', $name)) {
$headers[$name] = $value;
}
}
$logData = [
date('Y-m-d H:i:s'),
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI'],
json_encode($_POST, JSON_UNESCAPED_UNICODE),
json_encode($headers, JSON_UNESCAPED_UNICODE)
];
fwrite($fp, implode("\t", $logData)."\n");
fclose($fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment