On my website users can enter a HTTP status code into a standard text input field. i.e, 200, 400, 404, 403 etc...
Is there any way to check if the HTTP status code is valid. For example if a user enters '123' it will return false. I currently cannot think of or find a way other than doing a large ugly if or switch statement.
For those using Symfony or Laravel, you can do the following :
use Illuminate\Http\Response;
function is_valid_http_status(int $code) : bool {
// thanks @James in the comments ^^
return array_key_exists($code, Response::$statusTexts);
}
Assuming that Response
is one of those:
Symfony\Component\HttpFoundation\Response
Illuminate\Http\Response
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With