I recently decided to send proper HTTP header from my PHP application.
Since I've never done that before, I have a couple of very basic questions.
Status codes 200 and 404 seem obvious.
But how about the other ones?
Is it allowed to/recommended/not recommended to use 403 for example, if the user has to log in via a HTML form in order to use the page?
How about 415 for file uploads? Would it be a good idea to set a 415 header if the user uploads an image with a non-supported extension, for example?
The full list of W3C recognised codes is here . The definitions contain clear guidance on when each code should and should not be used. Your suggested use of 403, for example, is at odds with the W3C definition.
It depends on application you creating.
If you creating restfull app Its mandatory to use proper status codes. But when you creating backend generated web site Its up to you how you handle client/server errors and routing.
I think its only one rule to do -for a good user experience - handle all errors, the proper way (if 401 then redirect to login etc.)
I think you should use these status codes for a typical website:
If you're building a REST webservice, you can use some more status codes. But for a typical website the status codes listed above are fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.