How does the HTTP protocol handle responses from the server to the client?

The HTTP protocol handles responses from the server to the client by sending a status code along with the response data. The status code indicates the success or failure of the request, with common codes like 200 for success, 404 for not found, and 500 for server errors. The response data can be in various formats such as HTML, JSON, or XML, depending on the request.

<?php
// Send a successful response with a status code of 200 and JSON data
header("Content-Type: application/json");
echo json_encode(["message" => "Success"]);
http_response_code(200);
?>