Skip to content

Instantly share code, notes, and snippets.

@dexit
Forked from vmrfriz/webhook_log.php
Created May 7, 2024 16:15
Show Gist options
  • Save dexit/bc413d52c6d9de8fa0aa3ca8fcbf826f to your computer and use it in GitHub Desktop.
Save dexit/bc413d52c6d9de8fa0aa3ca8fcbf826f to your computer and use it in GitHub Desktop.
Webhook logging
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$filename = __DIR__ . '/request_log/' . date('Y-m-d_H-i-s') . '.log';
$path = dirname($filename);
if (!file_exists($path) || !is_dir($path)) {
mkdir($path, 0777, true);
}
$method = $_SERVER['REQUEST_METHOD'];
$protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === 0 ? 'https://' : 'http://';
$domain = $_SERVER['HTTP_HOST'];
$uri = $_SERVER['REQUEST_URI'];
$str = "{$method} {$protocol}{$domain}{$uri}\n\n" .
'HEADERS: ' . var_export(getallheaders(), true) . "\n\n" .
"BODY:\n" . file_get_contents('php://input') . "\n";
file_put_contents($filename, $str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment