hoku-lib / httpstatuscoderesolver
HttpStatusCodeResolver is a library for obtaining information on the HTTP status code.
v1.0.0
2018-11-15 14:20 UTC
Requires
- php: >=5.6.0
This package is auto-updated.
Last update: 2024-04-16 02:40:27 UTC
README
HttpStatusCodeResolver is a library for obtaining information on the HTTP status code.
Installation
The recommended way to install HttpStatusCodeResolver is through Composer.
composer require hoku-lib/httpstatuscoderesolver
Usage
Get a message.
<?php require_once 'vendor/autoload.php'; $statusCodeInfo = \HttpStatusCodeResolver\HttpStatusCode::resolve(400); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Demo</title> </head> <body> <?php if ($statusCodeInfo) : ?> <div><?=$statusCodeInfo[0]?></div> <div><?=$statusCodeInfo[1]?></div> <?php else : ?> <div>I do not know!</div> <?php endif; ?> </body> </html>
Output header.
<?php require_once 'vendor/autoload.php'; \HttpStatusCodeResolver\HttpHeader::http_response_code(403); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Demo</title> </head> <body> <h1>Forbidden!!!!</h1> </body> </html>
Original status code (When using http_response_code().)
<?php require_once 'vendor/autoload.php'; http_response_code(987); // -> HTTP/1.1 500 Internal Server Error // Oh my God!!!! // PHP converts the status code to 500... ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Demo</title> </head> <body> <div>Oh no...</div> </body> </html>
Original status code (When using HttpHeader::http_response_code().)
<?php require_once 'vendor/autoload.php'; \HttpStatusCodeResolver\HttpHeader::http_response_code(987, 'MyOriginalCode'); // -> HTTP/1.1 987 MyOriginalCode // Yay! Happy! -> ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Demo</title> </head> <body> <div>Yay!!!!</div> </body> </html>
License
HttpStatusCodeResolver is released under the MIT License. See the LICENSE file for details.