HTTP 403 Forbidden

The HTTP 403 status code indicatss that the server understood the request, but is refusing to fulfill it. Learn more in this tutorial.

1659 views

Edited: 2019-11-23 07:07

The HTTP 403 Forbidden error response is used when the server understood the request, but is refusing to fulfill it for some reason. This error is often encountered when entering a wrong username or password on a website.

Sometimes you may want to show a soft 403 Forbidden error, so that automated spam-bots gets confused. Soft errors will usually just send a 200 OK response instead of the real error – this is done to break certain bots and hacker tools.

Send a 403 from PHP

To send a 403 response from PHP, you can use the header function like this:

$Error_Page_Content = '';
header('HTTP/1.1 403 Forbidden');
echo $Error_Page_Content;

Note. If you want to deliver a custom error page, then it should be outputted after sending the headers. You should fill $Error_Page_Content with your own HTML.

More

  1. Creating a Custom Error Page – How to create a custom error page
  2. HTTP Response Codes – A list of HTTP Response Codes
  3. PHP Header – How to deliver status codes with PHP

Tell us what you think:

  1. An in-dept look at the use of headings (h1-h6) and sections in HTML pages.
  2. Pagination can be a confusing thing to get right both practically and programmatically. I have put a lot of thought into this subject, and here I am giving you a few of the ideas I have been working with.
  3. The best way to deal with a trailing question mark is probably just to make it a bad request, because it is a very odd thing to find in a request URL.
  4. How to optimize image-loading and automatically include width and height attributes on img elements with PHP.
  5. HTTP headers are not case-sensitive, so we are free to convert them to all-lowercase in our applications.

More in: Web development