How to send HTTP response code in API Using PHP?

#14
162
1 Answer
Question Image

I have a PHP Code that want to create responses with HTTP response codes (status-codes) in API, like HTTP 200 OK, or some 4XX or 5XX response code.

How I can do this using PHP?


Related to:
phphttp-response-codeapi
0
Answer
Answer 1 of 1
# 21

Return Custom Status with any HTTP Response Code

If you want to return a custom response using the HTTP response code in your page, use the following PHP code:

<?php
http_response_code();
?>

How to return 404 response code

For example, if you want to return a 404 code response, use code like this:

<?php
http_response_code(404);
?>
0
0
0
Related Articles

If you still have a question about this, submit it in our Q&A community - Ask Question