diff options
-rw-r--r-- | .gitignore | 9 | ||||
-rw-r--r-- | public/error/error.html | 225 |
2 files changed, 5 insertions, 229 deletions
@@ -1,6 +1,7 @@ /vendor -AppConfig.php /node_modules -public/js/app.js -public/dist -public/error/error.json +/public/dist +/public/error/error.json +/public/error/error.html +/bootstrap/comments/comments +AppConfig.php diff --git a/public/error/error.html b/public/error/error.html deleted file mode 100644 index 14467d7..0000000 --- a/public/error/error.html +++ /dev/null @@ -1,225 +0,0 @@ -<?php - -/** - * Web Server HTTP status code response test - * - * For PHP applications that run on a web server that intercepts all - * fast-cgi errors with the appropriate Http error template response. This program - * will run through given HTTP error response codes. - * - * @author Thedro Neely <thedroneely@gmail.com> - * - * @copyright Copyright 2018, Thedro Neely. - * @license https://github.com/tdro - * @link https://github.com/tdro - */ - -declare(strict_types=1); - -$path = $_SERVER['DOCUMENT_ROOT']; -$errorJsonFile = $path . '/error/error.json'; -$errorFile = $path . '/error/error.html'; -$debug = true; - -$errorList = [ - 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, - 410, 411, 412, 413, 414, 415, 416, 417, 418, 421, - 422, 423, 424, 426, 428, 429, 431, 451, 500, 501, - 502, 503, 504, 505, 511, 520, 522, 524 -]; - -$parameters = [ - 'HttpResponseCode' => (int) $errorList[0], - 'Run' => (int) 1, -]; - -/** - * Functions - */ - -function read($file) { - return json_decode(file_get_contents($file), true); -} - -function write($file, $json) { - file_put_contents($file, json_encode($json), 0); -} - -function debug ($message, $debug) { - if ($debug) { - echo '<pre>' . $message . '</pre>'; - } -} - -/** - * Inline CSS styling - */ - -echo ' - <style> - - pre { - background-color: black; - color: white; - max-width: 20em; - padding: 0.5em; - z-index: 10; - } - - form { z-index: 10; } - - </style> -'; - -/** - * Forms - */ - -if (isset($_POST["stop"])) { - $parameters['Run'] = 0; -} - -if (isset($_POST["start"])) { - $parameters['Run'] = 1; -} - -if ($parameters['Run'] === 1) { - echo ' - <form action="/error/error.html" method="post" id="stop"> - <input type="hidden" name="stop" value=stop> - </form> - - <button type="submit" form="stop">Stop</button> - '; -} - -if ($parameters['Run'] === 0) { - echo ' - <form action="/error/error.html" method="post" id="start"> - <input type="hidden" name="start" value=start> - </form> - - <form action="/error/error.html" method="post" id="previous"> - <input type="hidden" name="previous" value=previous> - </form> - - <form action="/error/error.html" method="post" id="next"> - <input type="hidden" name="next" value=next> - </form> - - <button type="submit" form="start">Start</button> - <button type="submit" form="previous"><</button> - <button type="submit" form="next">></button> - '; -} - -/** - * Json File - */ - -if (!file_exists($errorJsonFile)) { - - debug('Socket file does not exist. Creating...', $debug); - write($errorJsonFile, $parameters); - - if (!file_exists($errorJsonFile)) { - debug('Socket file creation failed!', $debug); - return; - } -} - -/** - * Error Code and Array Keys - */ - -$getError = read($errorJsonFile)['HttpResponseCode']; -debug('Current Error Code: ' . $getError . '<br>', $debug); - -$currentErrorKey = array_search($getError, $errorList); -$nextErrorKey = $currentErrorKey + 1; - -$getErrorTotal = count($errorList) - 1; -debug('Error List Count: ' . ($currentErrorKey + 1) . '/' . ($getErrorTotal + 1), $debug); - -/** - * Error Run - */ - -if ($nextErrorKey <= $getErrorTotal) { - - if ($parameters['Run'] === 1) { - echo '<meta http-equiv="refresh" content="1; url=/error/error.html">'; - } - - foreach ($parameters as $parameter) { - $parameters['HttpResponseCode'] = $errorList[$nextErrorKey]; - } - - write($errorJsonFile, $parameters); - var_dump(read($errorJsonFile)); - var_dump($_POST); - - /** - * Send HTTP response code - */ - - http_response_code((int) $getError); - return; - -} - -write($errorJsonFile, $parameters); -debug('Error run completed.', $debug); -var_dump($parameters); - -/** - * Http Response Template Files - */ - -$http_response_status = [ - 400 => "Bad Request", - 401 => "Unauthorized", - 402 => "Payment Required", - 403 => "Forbidden", - 404 => "Not Found", - 405 => "Method Not Allowed", - 406 => "Not Acceptable", - 407 => "Proxy Authentication Required", - 408 => "Request Timeout", - 409 => "Conflict", - 410 => "Gone", - 411 => "Length Required", - 412 => "Precondition Failed", - 413 => "Payload Too Large", - 414 => "Requested URI Too Long", - 415 => "Unsupported Media Type", - 416 => "Requested Range Not Satisfiable", - 417 => "Expectation Failed", - 418 => "I'm a teapot", - 421 => "Misdirected Request", - 422 => "Unprocessable Entity", - 423 => "Locked", - 424 => "Failed Dependency", - 426 => "Upgrade Required", - 428 => "Precondition Required", - 429 => "Too Many Requests", - 431 => "Request Header Fields Too Large", - 444 => "Connection Closed Without Response", - 451 => "Unavailable For Legal Reasons", - 500 => "Internal Server Error", - 501 => "Not Implemented", - 502 => "Bad Gateway", - 503 => "Service Unavailable", - 504 => "Gateway Timeout", - 505 => "HTTP Version Not Supported", - 506 => "Variant Also Negotiates", - 507 => "Insufficient Storage", - 508 => "Loop Detected", - 510 => "Not Extended", - 511 => "Network Authentication Required", -]; - -// var_dump($http_response_status); -// echo key($http_response_status); - -?> |