Created
May 7, 2025 12:05
-
-
Save ideadude/8d5c4af7c3bad4de391e458d91e54b05 to your computer and use it in GitHub Desktop.
Dummy webhook handler for testing. Saves incoming data to a file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Just place this file on the webserver and then point your webhook to the location. | |
* This will save the incoming timestamp and data to a webhook-handler.log file in the same folder. | |
* Use `tail -f webhook-handler.log` to monitor the log file. | |
*/ | |
// Set the log file path | |
$logFile = __DIR__ . '/webhook-handler.log'; | |
$timestamp = date('Y-m-d H:i:s'); | |
// Read raw POST body | |
$rawInput = file_get_contents('php://input'); | |
// Try to decode JSON if it exists | |
$jsonData = json_decode($rawInput, true); | |
// Prepare formatted data for logging | |
$requestData = [ | |
'timestamp' => $timestamp, | |
'raw_input' => $rawInput, | |
'json_decoded' => $jsonData, | |
'_REQUEST' => $_REQUEST, | |
]; | |
// Convert to readable format | |
$logEntry = "[" . $timestamp . "] Incoming Request:\n" . print_r($requestData, true) . "\n----------------------\n"; | |
// Write to the log | |
file_put_contents($logFile, $logEntry, FILE_APPEND | LOCK_EX); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment