Example 1 — Set and Read a Status Code
Set 404, then read the current code back for display.
<?php
http_response_code(404);
echo http_response_code(), PHP_EOL; How It Works
- http_response_code(404) sets the Not Found status.
- Calling it again with no argument reads the current code.
- echo prints 404.
- On some CLI builds the get may differ; web SAPIs keep the value you set.

