$data = file_get_contents('php://input'); if ($data) file_put_contents( 'unisender/status.txt', ' php://input ', FILE_APPEND | LOCK_EX); if (!$data) file_put_contents( 'unisender/status.txt', ' NOT php://input ', FILE_APPEND | LOCK_EX); 

The Unisender service sends events via webhooks format via the webhooks API. The above script writes to the file for all events "NOT php://input" , that is, it does not receive data through php://input .

How to get webhooks in json format?

    1 answer 1

    Support example:

      class hook { public function handle($receiver_path) { $filename = basename($receiver_path, '.php'); $api_key = "'';// ваш api_key $postData = file_get_contents('php://input'); if (strlen($postData) > 0) { $decodedData = json_decode($postData, true); if ($decodedData == '') { $decodedData = json_decode(gzdecode($postData), true); } $hash = $decodedData['auth']; $decodedData['auth'] = $api_key; file_put_contents('/tmp/__'.$filename. '__' .time(). '.log', var_export($decodedData, true) . "nn Hash received: {$hash}n Hash verifying: " .md5(json_encode($decodedData))); } else { $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_U RI]"; file_put_contents('/tmp/GET__'.$filename. '__' .time(). '.log', $actual_link, FILE_APPEND); echo 'Yep! It works! Filename: '.$filename; } } } 

    From it it is visible that the empty hook can come.

    It is also likely on older versions, since we do not receive a leader with multi-part / form-data, it may be that the input is empty: https://stackoverflow.com/a/20148962/5892568

    Therefore, it may possibly help: http://php.net/manual/en/ini.core.php#ini.enable-post-data-reading

    When this option is disabled, the superglobal variables $ _POST and $ _FILES will not be populated. The only way to read the POST data is to read the stream wrapper php: // input. This can be useful when proxying requests or processing POST data in a way that uses memory more efficiently.

    • corresponded with support, hosting is ok. No one can say why the data does not come or how to accept them. In this case, the POST method receives data. if (isset($_POST) && !empty($_POST)) { file_put_contents('unisender/status.txt', ' post ', FILE_APPEND | LOCK_EX); } if (isset($_POST) && !empty($_POST)) { file_put_contents('unisender/status.txt', ' post ', FILE_APPEND | LOCK_EX); } - Gregory
    • I think we should look: - Serge Markov
    • What version of PHP and in what environment is running ... apache, php_fpm. suppose you have denver / with old php? - Serge Markov