Skip to content

Instantly share code, notes, and snippets.

@silverfoxy
Last active January 5, 2022 06:42
Show Gist options
  • Select an option

  • Save silverfoxy/780995e3553b8059eb73ca29a6cb2df5 to your computer and use it in GitHub Desktop.

Select an option

Save silverfoxy/780995e3553b8059eb73ca29a6cb2df5 to your computer and use it in GitHub Desktop.
Extended logs
<?php
// gather_logs();
function gather_logs() {
if (!isset($_SESSION)) { session_start(); }
$session_keys = array_keys($_SESSION);
$session = [];
foreach ($session_keys as $key) {
$session[$key] = "dummy";
}
$cookie_keys = array_keys($_COOKIE);
$cookie = [];
foreach ($cookie_keys as $key) {
$cookie[$key] = "dummy";
}
$post_keys = array_keys($_POST);
$post = [];
foreach ($post_keys as $key) {
$post[$key] = "dummy";
}
$files_keys = array_keys($_FILES);
$files = [];
foreach ($files_keys as $key) {
$files[$key] = "dummy";
}
$log_line = ['request_method'=>$_SERVER['REQUEST_METHOD'],
'request_uri'=>$_SERVER['REQUEST_URI'],
'script_filename'=>$_SERVER['SCRIPT_FILENAME'],
'session'=>$session,
'cookie'=>$cookie,
'get'=>$_GET,
'post'=>$post,
'files'=>$files];
file_put_contents('/var/www/html/log.txt', serialize($log_line).PHP_EOL, FILE_APPEND);
file_put_contents('/var/www/html/log.txt', '----'.PHP_EOL, FILE_APPEND);
}
register_shutdown_function('gather_logs');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment