index3.php - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of index3.php.php

  1. <?php
  2. // Initialize cURL and make the request
  3. $ch = curl_init();
  4. curl_setopt($ch, CURLOPT_URL, 'https://affiliateads.api.hasoffers.com/Apiv3/json?NetworkToken=NETk68QSu1uuJ3zxpKsej0oDAODYB5&Target=Report&Method=getModSummaryLogs&fields[]=ModSummaryLog.country_code&fields[]=ModSummaryLog.message&fields[]=Offer.name&fields[]=ModSummaryLog.type&filters[ModSummaryLog.type][conditional]=EQUAL_TO&filters[ModSummaryLog.type][values]=error&sort[ModSummaryLog.date]=desc');
  5. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6. $response = curl_exec($ch);
  7. curl_close($ch);
  8.  
  9. // Decode the response into a PHP associative array
  10. $response = json_decode($response, true);
  11.  
  12. // Make sure that there wasn't a problem decoding the repsonse
  13. if(json_last_error()!==JSON_ERROR_NONE){
  14.         throw new RuntimeException(
  15.                 'API response not well-formed (json error code: '.json_last_error().')'
  16.         );
  17. }
  18.  
  19. // Print out the response details or, any error messages
  20. if(isset($response['response']['status']) && $response['response']['status']===1){
  21.         echo 'API call successful';
  22.         echo PHP_EOL;
  23.         echo 'Response Data: <pre>'.print_r($response['response']['data'], true).'';
  24.         echo PHP_EOL;
  25. }else{
  26.         echo 'API call failed'.(isset($response['response']['errorMessage'])?' ('.$response['response']['errorMessage'].')':'').'';
  27.         echo PHP_EOL;
  28.         echo 'Errors: <pre>'.print_r($response['response']['errors'], true).'';
  29.         echo PHP_EOL;
  30. }
  31. ?>
File Description
  • index3.php
  • PHP Code
  • 27 Jan-2020
  • 1.38 Kb
You can Share it: