Skip to content

Instantly share code, notes, and snippets.

@AaEzha
Last active July 12, 2023 02:25
Show Gist options
  • Select an option

  • Save AaEzha/b40183b9b7299c996051ebee31358fa5 to your computer and use it in GitHub Desktop.

Select an option

Save AaEzha/b40183b9b7299c996051ebee31358fa5 to your computer and use it in GitHub Desktop.
Example of webhook client
<?php
// Retrieve the webhook payload
$payload = file_get_contents('php://input');
// Process the webhook payload
// ... Perform any necessary actions or data processing based on the received payload
// Prepare the response data
$responseData = [
'status' => 'success',
'message' => 'Webhook received successfully',
];
// Convert the response data to JSON
$responseJson = json_encode($responseData);
// Set the response headers
header('Content-Type: application/json');
header('Content-Length: ' . strlen($responseJson));
// Send the response
echo $responseJson;
<?php
$data = file_get_contents("php://input");
$events = json_decode($data, true);
$mysqli = new mysqli("localhost","db_username","db_password","db_name");
// Check connection
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
$test = $mysqli -> query("insert into trx (keterangan) values ('$data')");
if ($test) {
$mysqli -> query("insert into trx (keterangan) values ('Tes berhasil')");
} else {
$mysqli -> query("insert into trx (keterangan) values ('Tes gagal')");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment