Last active
June 28, 2023 16:52
-
-
Save FerraBraiZ/c9648061bf9181a1b7d70df7002b17d8 to your computer and use it in GitHub Desktop.
POST Webhook
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 | |
if ('POST' !== $_SERVER['REQUEST_METHOD']) { | |
http_response_code(405); | |
exit( json_encode([ 'Client Error 405' => 'Method not allowed!' ]) ); | |
} | |
try { | |
$incomingData = file_get_contents("php://input"); | |
if( !isset( $incomingData ) ) { | |
http_response_code(204); | |
exit( json_encode([ "response" => "no content was sent to this endpoint" ]) ); | |
} | |
$file = new \SplFileObject( 'ReceivedData.log', 'a'); | |
$file->fwrite( date('{ d-m-y-H-m-s },') ); | |
$file->fwrite( PHP_EOL ); | |
$file->fwrite( $incomingData ); | |
$file->fwrite( date(',') ); | |
http_response_code(200); | |
exit( json_encode([ "response" => "everything is gonna be 200!" ]) ); | |
} catch( Exception $e) { | |
$error = new \SplFileObject('error-'.date('d-m-y-H-m-s').'.log', 'a'); | |
$file->fwrite( PHP_EOL ); | |
$file->fwrite( $e ); | |
$file->fwrite( PHP_EOL ); | |
http_response_code(500); | |
exit( json_encode([ 'Client Error 500' => 'Unknown Internal Error! No additional error messages or exceptions were provided.' ]) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment