<?php
// Set the content type to application/json
header("Content-Type: application/json");

// Get the raw POST data
$data = file_get_contents("php://input");

// Decode the JSON data
$json_data = json_decode($data, true);

// Check if the data is decoded successfully
if (json_last_error() === JSON_ERROR_NONE) {
    // Access the data
    $name = $json_data['name'];
    $age = $json_data['age'];
    $city = $json_data['city'];

    // Respond back
    $response = [
        'status' => 'success',
        'message' => 'Data received',
        'received' => [
            'name' => $name,
            'age' => $age,
            'city' => $city
        ]
    ];

    echo json_encode($response);
} else {
    // Respond with an error if JSON is invalid
    echo json_encode([
        'status' => 'error',
        'message' => 'Invalid JSON'
    ]);
}
?>
