General explanation of the 204 status code
The HTTP status code 204 No Content means that the server has successfully processed the request, but there is no data to send back. In other words, everything worked, but there is no information (content) to send in response. It's like you ask someone what time it is, and instead of telling you what time it is, they just nod to confirm that they heard you, but don't give you a specific answer.
.Specification of the HTTP status code 204
The 204 No Content status code indicates that the server has successfully fulfilled the request and that there is no additional content to send in the response payload body. Metadata in the response header fields refer to the target resource and its selectedrepresentation after the requested action was applied.
For example, if a 204 No Content status code is received in response to a PUT request and the response contains an ETag header field, then the PUT was successful and the ETag field-value contains the entity-tag for the new representation of that target resource.
The 204 No Content response allows a server to indicate that the action has been successfully applied to the target resource, while implying that the user agent does not need to traverse away from its current "document view" (if any). The server assumes that the user agent will provide some indication of the success to its user, in accord with its own interface, and apply any new or updated metadata in the response to its active representation.
For example, a 204 No Content status code is commonly used with document editing interfaces corresponding to a "save" action, such that the document being saved remains available to the user for editing. It is also frequently used with interfaces that expect automated data transfers to be prevalent, such as within distributed version control systems.
A 204 No Content response is terminated by the first empty line after the header fields because it cannot contain a message body.
A 204 No Content response is cacheable by default; i.e., unless otherwise indicated by the method definition or explicit cache controls (see Section 4.2.2 of [RFC7234]).
Source / Quote by: The 204 No Content HTTP Status Code is specified by section 6.3.5 of RFC7231.
HTTP-Protocol
How to throw a 204 statuscode with PHP?
To throw the HTTP status code 204 on a web page, the PHP function http_response_code can be used. The syntax is as follows: http_response_code(204) (PHP 5 >= 5.4.0, PHP 7, PHP 8)
Test the 204 HTTP status code
In order to be able to display the HTTP status code (in this case 204 No Content) and other information on the client side, the development console must be opened with F12. Afterwards you have to navigate to the tab "Network". Now you can open the page, in the network tab you should see the web page (example index.php). This must be selected and then the Herder section must be selected. Here the user will see the following result:
URL: https://http-statuscode.com/errorCodeExample.php?code=204
Status: 204 No Content
Those: Network
IP address: XX.XX.XX.XX
Browser compatibility of the 204 status code
Chrome | Yes |
Edge | Yes |
Firefox | Yes |
Opera | Yes |
Safari | Yes |
Chrome Android | Yes |
Firefox for Android | Yes |
Opera Android | Yes |
Safari on iOS | Yes |
Internet | Yes |
WebView Android | Yes |
Constants in programming languages
External links with more information about HTTP status code 204:
Funny memes about HTTP status code 204
Blog Articles
SEO and HTTP status codes: A comprehensive analysis
Optimizing a website for search engines (SEO) is a complex undertaking. One of the often overlooked but crucial aspects for a good ranking are HTTP status codes. These small, three-digit codes info...