index2.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 index2.php.php

  1. <?php
  2. $contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
  3.  
  4. if ($contentType === "application/json") {
  5.   //Receive the RAW post data.
  6.   $content = trim(file_get_contents("php://input"));
  7.  
  8.   $decoded = json_decode($content, true);
  9.  
  10.   //If json_decode failed, the JSON is invalid.
  11.   if(! is_array($decoded)) {
  12.  
  13.   } else {
  14.     // Send error back to user.
  15.   }
  16. }
  17. ?>
  18.  
  19. <script>
  20.       fetch("/", {
  21.     method: "POST",
  22.     mode: "same-origin",
  23.     credentials: "same-origin",
  24.     headers: {
  25.       "Content-Type": "application/json"
  26.     },
  27.     body: JSON.stringify({
  28.       "payload": myObj
  29.     })
  30.   })
  31. </script>
File Description
  • index2.php
  • PHP Code
  • 27 Jan-2020
  • 634 Bytes
You can Share it: