Search code examples
httphttp-headershttp-status-codeshttp-status-code-401http-status-code-400

HTTP/1.1 status headers, when to use which?


Okay, I am working on an admin panel right now, so I came across stumbling, kind of.

Form: http://pastebin.com/D8Dt6zP5

Processing Page: http://pastebin.com/FpXSziPM

Now, onto the problem, I just used 403 Forbidden header when the expected values weren't found in the $_GET, but, when thought for, it isn't really an action that requires login(not for this, ofcourse a user have to login to view the admin panel in the first place), it's more like an unexpected value input.

So I have gone and made a research, in the brief explanations of each, I elected these headers which might be suitable.

I refer from this, looking out by groups of each status code, this should belong in 4XX codes.

So going deeper, and I elect these two:

400 Bad Request: The request cannot be fulfilled due to bad syntax

417 Expectation Failed: The server cannot meet the requirements of the Expect request-header field

Now, I cannot be really sure which one to use, I have seen 400 Bad Request being used alot, however, whatI get from explanation is that the error is due to an unexistent request rather than an illegal input.

On the other side 417 Expectation Failed seems to just fit for my use, however, I have never seen or experimented this header status before.

As I side note, as of the explanation in Wikipedia for 403, I can see it's extremely wrong for this, like I thought, I should probably be using 401 for the views without login, and 403 for a logged user which doesn't have access to a certain area.

So I really need your opinions, thanks by now.

Regards, TheDeadLike.


Solution

  • I have found my answer; thanks for the interest.

    You can see the answer here.