<?php // Only allow POST requests $response=new stdClass(); //you may get a warning , otherwise . header('Content-Type: application/json'); //gonna send everything as JSON response.. so, anyways if (strtoupper($_SERVER['REQUEST_METHOD']) != 'POST') { http_response_code(405); $response->status="failed"; $response->message="Method Not Allowed"; echo json_encode($response); exit(); } // Make sure Content-Type is application/json $content_type = isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : ''; if (stripos($content_type, 'application/json') === false) { $response->status="failed"; $response->message="Content-Type must be application/json"; http_response_code(415); echo json_encode($response); exit(); } // Read the input stream $request_body = file_get_contents("php://input"); // Decode the JSON object $data = json_decode($request_body, true); // Throw an exception if decoding failed if (!is_array($data)) { $response->status="error"; $response->message="Invalid JSON"; http_response_code(400); echo json_encode($response); exit(); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Just In Case, If anyone need this