Reputation: 95
I have a page in php that I want no access to it except my application. if there is not session predefined I sent header location.
Then I thought using
header("HTTP/1.1 401 Unauthorized");
exit();
All working well and I can add my own "Unauthorized Message" I want. But why? I can easily not send any header (default will be 200) still with my "Unauthorized Message".
What is the point telling the browser the status code if it doesn't do anything?
Edit: I want to explain myself better. It doesn't matter if it's 404, 403 or 500. The browser will not show any message by it self, And if I won't use the exit it will keep render the rest of the page. so how it helps me to send the header?
Upvotes: 1
Views: 84
Reputation: 13725
The 401 status code will trigger an authentication popup on client side. (The WWW-Authenticate header is also needed for this...)
Details for example here:
http://en.wikipedia.org/wiki/Basic_access_authentication
Upvotes: 2