20/03
2017
Wallogit.com
2017 © Pedro Peláez
Simple PHP class for handling HTTP response right way.
Simple PHP class to handle responses correctly., (*1)
composer require iothost/phpresponse, (*2)
$loader = require './vendor/autoload.php';
$response = new \Iothost\PhpResponse\Response();
// add header
$response->addHeader('Cache-Control: no-cache');
// set Content-Type, can be entered as a string
$response->addHeader($response::CT_TEXT);
// set HTTP status code, can be entered as a number (int)
$response->setStatus($response::STATUS_OK);
// set response body as a string
$response->setBody($string);
// OR
// set response body as JSON (from array)
$response->setBodyJson($array);
// send response
$response->send();