Alexya's HTTP components
Alexya's HTTP components, (*1)
The class \Alexya\Http\Request
offers a wrapper for the request supergloblas ($_GET
, $_POST
...)., (*3)
You can retrieve the request with the method main
., (*4)
The constructor accepts the following parameters:, (*5)
Example:, (*6)
<?php $request = new \Alexya\Http\Request( $_SERVER["REQUEST_URI"], $_GET, $_POST, $_COOKIES, $_FILES, $_SERVER ); // Which is the same as `$request = \Alexya\Http\Request::main();` echo $request->get["param_name"]; foreach($request->headers as $key => $value) { echo "Requested header: {$key}: {$value}"; }
The class \Alexya\Http\Response
offers a way for create and send HTTP responses., (*8)
The constructor accepts the following parameters (all of them optional):, (*9)
To send the request use the method send
., (*10)
To add a new header use the method header
which accepts as parameter a string being the header
name and a string or an array being the value of the header., (*11)
The method status
sets the status code of the response, it can be either an integer being
the code or a string being the name (see Response::responseCodes
)., (*12)
The method redirect
sends a redirect response thrugh headers.
It accepts as parameter a string being the URL to redirect, a string being the method of redirect
("Refresh" or "Location") and the status code of the redirect., (*13)
Example:, (*14)
<?php $request = new Request(); $request->header("Content-Type", "text/html"); $request->status(200); $request->body("Hello World
"); Request::redirect("/Home");