php
post-request http-methods server-side-handling get-request json-encode json-decode file-get-contents php-server-side-logic
Published on January 26, 2024By DeveloperBreeze
// index.php
$method = $_SERVER['REQUEST_METHOD'];
if ($method === 'GET') {
// Handle GET request
echo json_encode($data);
} elseif ($method === 'POST') {
// Handle POST request
$data = json_decode(file_get_contents('php://input'), true);
echo json_encode(['message' => 'Data received.']);
}
// Add similar blocks for other HTTP methods
Comments
Please log in to leave a comment.