Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created March 17, 2023 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sibelius/0958ca0c74ac31050ec555a76cd16d7b to your computer and use it in GitHub Desktop.
Save sibelius/0958ca0c74ac31050ec555a76cd16d7b to your computer and use it in GitHub Desktop.
simple php post
<?php
// Set headers to allow cross-origin resource sharing (CORS)
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
// Get the JSON data sent in the request body
$request_body = file_get_contents('php://input');
// Decode the JSON data into a PHP object
$data = json_decode($request_body);
// Process the data (e.g. save it to a database)
// ...
echo json_encode($data);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment