Jet\Http_Headers
As the name of the class suggests, it is used for working with HTTP headers, more precisely for sending response headers and very often for various redirects and so on.
Method | Meaning of |
---|---|
public static response( int $code, array $headers = [], string $custom_response_message='' ): void |
Builds and sends an HTTP response. Parameters:
|
public static redirect( int $http_code, string $target_URL, array $headers = [], bool $application_end = true ): void |
Redirects to the URL using an optional HTTP return code. For example:
Http_Headers::redirect(
Using the headers parameter it is possible to define additional optional headers (the principle is the same as for the response method). The $application_end parameter determines whether the application should be terminated after redirection. |
public static movedPermanently( string $target_URL, array $headers = [], bool $application_end = true ): void |
Identical method as redirect, except that the HTTP code 301 is used automatically. |
public static movedTemporary( string $target_URL, array $headers = [], bool $application_end = true ): void |
Identical method as redirect, except that the HTTP code 302 is used automatically. |
public static reload( array $set_GET_params = [], array $unset_GET_params = [], ?string $set_anchor = null, bool $application_end = true ): void |
Probably the most commonly used method of this class. It is used, for example, after submitting a form (most often by the POST method) or generally performing some action. For example, the user has submitted an article using a form (POST method), the article is added and you would need to redirect the user to the detail (editing) of this newly added article. In such a situation you would need to redirect (probably) to the same URL, with the difference that, for example, you add a new value to the GET parameters, or on the contrary, you remove a value from the existing parameters. Let's see some practical examples. Suppose that the GET parameter delete is to perform the action of deleting an article. The URL can then be: https://some.domain/armin/articles/?delete=123 Your controller will handle everything, delete the article and needs to get the user to the article list. So to the URL https://some.domain/armin/articles/. He'll do it like this:
Http_Headers::reload(unset_GET_params: ['delete']);
And the second example. A new article has been added and you want to send the user directly to edit it, i.e. to the URL https://some.domain/armin/articles/?id=123 Here's how you do it:
Http_Headers::reload(set_GET_params: ['id'=>$id]);
|
public static sendDownloadFileHeaders( string $file_name, string $file_mime, int $file_size, bool $force_download = false ): void |
If you need to send a file to a user (download, etc.), you need to build the HTTP headers correctly. This method will do it for you. You can use the method on its own, or you can leave everything to the Jet\IO_File::send() method, which just "passes" the file and takes care of everything. |