402

Payment Required

Official
a payment is required

General explanation of the 402 status code

The HTTP status code 402 Payment Required indicates that the requested resource or service is only available if a payment is made. This status code is typically used in situations where payment is required to access the requested content or functionality.

The 402 Payment Required status code is typically used by websites or web applications that offer paid services. When a user wants to access a resource or feature that requires payment, but has not yet made a payment, the server may return the 402 Payment Required status code. This indicates that the user must make a payment to gain access.

In most cases, the server will also provide other information in the response text, such as instructions for making the payment or links to payment options. This allows the user to make the payment and then access the desired content or functionality.

It is important to note that the 402 Payment Required Payment Required status code was defined in the original HTTP/1.1 standard, but has not been widely used to date. Other status codes such as 403 Forbidden or 404 Not Found are more commonly used to handle similar situations.

Specification of the HTTP status code 402

Status code 402 Payment Required is reserved for future use. According to RFC 7231, the code is not yet in use.

Source / Quote by: The 402 Payment Required HTTP Status Code is specified by section 6.5.2 of RFC7231.

How to throw a 402 statuscode with PHP?

To throw the HTTP status code 402 on a web page, the PHP function http_response_code can be used. The syntax is as follows: http_response_code(402) (PHP 5 >= 5.4.0, PHP 7, PHP 8)

Test the 402 HTTP status code

In order to be able to display the HTTP status code (in this case 402 Payment Required) and other information on the client side, the development console must be opened with F12. Afterwards you have to navigate to the tab "Network". Now you can open the page, in the network tab you should see the web page (example index.php). This must be selected and then the Herder section must be selected. Here the user will see the following result:

Status code 402 Payment Required
Overview
URL: https://http-statuscode.com/errorCodeExample.php?code=402
Status: 402 Payment Required
Those: Network
IP address: XX.XX.XX.XX
Status code 402 Payment Required

How to create a custom error page for the 402 status code

Creating your own 402 Payment Required error page is relatively easy with the web server "Apache" as well as with the web server "NGINX".

Apache Webserver

The web server "Apache" is one of the most popular web servers on the Internet. To create an own 402 Payment Required error page in "Apache", the following change must be made in the following file.

File: .htaccess
ErrorDocument 402 /errors/402.html

NGINX Webserver

Similar to the web server "Apache", "NGINX" is also widely used on the Internet. To create your own 402 Payment Required error page in "NGINX", the following change must be made in the following file.

File: sites-enabled/default
error_page 402 /402.html;
location = /402.html {
    root /usr/share/nginx/html;
    internal;
}

Browser compatibility of the 402 status code

Chrome no data
Edge no data
Firefox no data
Opera no data
Safari no data
Chrome Android no data
Firefox for Android no data
Opera Android no data
Safari on iOS no data
Internet no data
WebView Android no data

Constants in programming languages

HttpStatusCode.PaymentRequired
http.StatusPaymentRequired
Response::HTTP_PAYMENT_REQUIRED
httplib.PAYMENT_REQUIRED
http.client.PAYMENT_REQUIRED
http.HTTPStatus.PAYMENT_REQUIRED
:payment_reqired

Blog Articles

The difference between HTTP status code 402 and 403

When we deal with the World Wide Web and the communication between servers and clients, we come across various status codes that describe the state of an HTTP request. Two of these status codes tha...

Author: Tony Brüser
Author: Tony Brüser

Tony Brüser is an enthusiastic web developer with a penchant for HTTP status codes.

LinkedInGitHub