Beamtic's logo

Share via:

HTTP 400 Bad Request

A 400 Bad Request response is used to indicate a problem happened due to something on the client-side.

55 views

Edited: 2020-09-06 09:58

A 400 Bad Request response is used when a client has sent a malformed request, such as when the request is missing a path, or when a unknown URL parameter has been used.

The path is usually never empty, since the HTTP protocol specifies that it must at least always include a forward slash "/"; but it is still possible to mess with a request before sending it, and something like a missing host header or path could cause a misconfigured server to present the wrong website; at least if the server is hosting multiple domains.

A 400 response looks like this in plain text:

HTTP/1.1 400 Bad Request

To send a custom 400 response code in PHP, use the http_response_code function:

http_response_code(400);
echo '<h1>400 Bad Request</h1>';

To instead send the raw headers see: The PHP Header Function

Comments