http_response_code example

if (function_exists('ini_set')) {
    @ini_set('display_errors', '1');
    @ini_set('display_startup_errors', '1');
    @ini_set('opcache.enable', '0');
    @ini_set('opcache.enable_cli', '0');
    @ini_set('max_execution_time', '300');
}

if (\PHP_VERSION_ID < 80100) {
    echo 'PHP 8.1 is required.';

    http_response_code(500);
    exit(1);
}

if (!extension_loaded('Phar')) {
    exit('The PHP Phar extension is not enabled.');
}

if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
    date_default_timezone_set('UTC');
}

'isNewer' => true,
    ], \JSON_THROW_ON_ERROR);
    exit;
}

if (str_starts_with($uri, '/update.zip')) {
    header('Content-Type: application/zip');
    echo file_get_contents($fileName);
    exit;
}

http_response_code(404);

    private function renderException(\Throwable $exception): void
    {
        $renderer = \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? new CliErrorRenderer() : new HtmlErrorRenderer($this->debug);

        $exception = $renderer->render($exception);

        if (!headers_sent()) {
            http_response_code($exception->getStatusCode());

            foreach ($exception->getHeaders() as $name => $value) {
                header($name.': '.$value, false);
            }
        }

        echo $exception->getAsString();
    }

    public function enhanceError(\Throwable $exception): \Throwable
    {
        
$filename = sanitize_filename('debugbar_' . $request->getGet('debugbar_time'));
            $filename = WRITEPATH . 'debugbar/' . $filename . '.json';

            if (is_file($filename)) {
                // Show the toolbar if it exists                 echo $this->format(file_get_contents($filename)$format);

                exit;
            }

            // Filename not found             http_response_code(404);

            exit; // Exit here is needed to avoid loading the index page         }
    }

    /** * Format output */
    protected function format(string $data, string $format = 'html'): string
    {
        $data = json_decode($data, true);

        

    private function renderException(\Throwable $exception): void
    {
        $renderer = \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) ? new CliErrorRenderer() : new HtmlErrorRenderer($this->debug);

        $exception = $renderer->render($exception);

        if (!headers_sent()) {
            http_response_code($exception->getStatusCode());

            foreach ($exception->getHeaders() as $name => $value) {
                header($name.': '.$value, false);
            }
        }

        echo $exception->getAsString();
    }

    /** * Override this method if you want to define more error enhancers. * * @return ErrorEnhancerInterface[] */
<?php endforeach; ?> </tbody> </table> <?php endif; ?> </div> <!-- Response --> <?php                 $response = Services::response();
                $response->setStatusCode(http_response_code());
            ?> <div class="content" id="response"> <table> <tr> <td style="width: 15em">Response Status</td> <td><?= esc($response->getStatusCode() . ' - ' . $response->getReasonPhrase()) ?></td> </tr> </table> <?php $headers = $response->headers(); ?> <?php if (empty($headers)) : ?>
$lastError = error_get_last();
            if (!\is_array($lastError)) {
                return;
            }

            switch ($lastError['type']) {
                case E_ERROR:
                case E_PARSE:
                case E_CORE_ERROR:
                    ob_clean();
                    ob_flush();
                    http_response_code(200);
                    $message = 'Error<br><br>' . $lastError['message'] . '<br><br>File:' . str_replace('/', '/ ', $lastError['file']);
                    echo json_encode(['success' => false, 'error' => $message]);
            }
        });
    }

    /** * Gets an array of plugins that are in Safe Mode * * @param array<Plugin> $plugins * * @return array<Plugin> */
Home | Imprint | This part of the site doesn't use cookies.