My PHP file to get Webhook seems not working on InfinityFree

so on my website, I created donor.php to listen to webhook sent from a Donation Services called Saweria, here’s my php script

<?php error_reporting(E_ALL); ini_set('display_errors', 1); // Allow Saweria IP only if ($_SERVER['REMOTE_ADDR'] != '159.65.8.77') { exit; } // Get raw data $raw_data = file_get_contents('php://input'); // Decode JSON $data = json_decode($raw_data, true); // Generate donation ID $donationId = rand(0, 9999); // Format amount $amount = round($data['amount_raw'] / 1000); // Create output $output = ''. ''. ''. '
IDAmountNameEmail
' . $donationId . '' . $amount . '' . $data['donator_name'] . '' . $data['donator_email'] . '
'; // Read existing contents $existing = file_get_contents('donations.html'); // Explode into array $donations = explode('', $existing); // Prepend new donation array_unshift($donations, $output); // Keep latest 5 $donations = array_slice($donations, 0, 5); // Implode back to string $donations = implode('', $donations); // Write back to file file_put_contents('donations.html', $donations); ?>

its a simple php script that listen to webhook then write it to donations.html on my folder directory, but I couldnt get the data on my donations.html. weirdly, it only occurs on InfinityFree, all hosting seems to be fine

whoops, sorry I use quotation on the wrong section.

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

// Allow Saweria IP only
if ($_SERVER['REMOTE_ADDR'] != '159.65.8.77') {
    exit;
}

// Get raw data
$raw_data = file_get_contents('php://input');

// Decode JSON 
$data = json_decode($raw_data, true);

// Generate donation ID
$donationId = rand(0, 9999);

// Format amount  
$amount = round($data['amount_raw'] / 1000);

// Create output
$output = '<table border="1">'. 
        '<tr><th>ID</th><th>Amount</th><th>Name</th><th>Email</th></tr>'.
        '<tr><td>' . $donationId . '</td><td>' . $amount . '</td><td>' . $data['donator_name'] . '</td><td>' . $data['donator_email'] . '</td></tr>'.  
        '</table>';

// Read existing contents
$existing = file_get_contents('donations.html'); 

// Explode into array
$donations = explode('<!--donation_separator-->', $existing);

// Prepend new donation
array_unshift($donations, $output);  

// Keep latest 5    
$donations = array_slice($donations, 0, 5);  

// Implode back to string
$donations = implode('<!--donation_separator-->', $donations);

// Write back to file
file_put_contents('donations.html', $donations);

?>

Add an echo statement before the exit statement to make sure this is not taking affect

If it still does not work, enable display errors under php config in the control panel and reload the page

6 Likes

I’ve tried both, still not working

Sounds like this, since you described as something like an external service sending things to your site:

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.