Handling an “Unauthorized” Error

As you learned earlier in the book, the 401 Unauthorized error is sent to the user when she fails to enter the correct username or password for a site that requires the user to log in. Unfortunately, the default error documents for the 401 error aren’t very descriptive, as you can see from Figure 23.7.

Figure 23.7. A standard error document from the 401 Unauthorized error.

If your site uses authentication, you should provide users with an error document that explains why access to the page wasn’t granted if they fail to log in correctly. Furthermore, if you run a public site, you should explain how users can ...

Get Sams Teach Yourself CGI in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.