http_response_code

The http_response_code function allows you to set your own HTTP response status code.

An example usage might be if you are using Routes to handle custom requests and you need to return a 404 response due to an issue with the request.

{% if value == 'some_required_value' %}
    {# DO SOMETHING THERE #}
{% else %}
    {# FAILED THE TEST. RETURN A 404 RESPONSE #}
    {% do http_response_code(404) %}
    Failed
{% endif %}

Arguments

The http_response_code function has the following signature.

http_response_code(numeric_response_code)
Argument Description
numeric_response_code

The numeric response code that is greater than 100 and less than 599. it should be a valid response code.

< Back to the list of functions