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
Source / Quote by: The 402 Payment Required HTTP Status Code is specified by section 6.5.2 of RFC7231.
HTTP-Protocol
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:
URL: https://http-statuscode.com/errorCodeExample.php?code=402
Status: 402 Payment Required
Those: Network
IP address: XX.XX.XX.XX
How to create a custom error page for the 402 status code
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.
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.
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
External links with more information about HTTP status code 402:
Funny memes about HTTP status code 402
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...