Hypertext Transfer Protocol (HTTP) utilities for PHP
- PHP 5.3.0+
-
Include the library via Composer [?]:
$ composer require delight-im/http
-
Include the Composer autoloader:
require __DIR__ . '/vendor/autoload.php';
-
Retrieving a header (with optional value prefix)
$header = \Delight\Http\ResponseHeader::get('Content-Type'); // or $header = \Delight\Http\ResponseHeader::get('Content-Type', 'text/');
-
Setting a header (overwriting other headers with the same name)
\Delight\Http\ResponseHeader::set('X-Frame-Options', 'sameorigin');
-
Adding a header (preserving other headers with the same name)
\Delight\Http\ResponseHeader::add('Vary', 'User-Agent');
-
Removing a header (with optional value prefix)
$success = \Delight\Http\ResponseHeader::remove('X-Powered-By'); // or $success = \Delight\Http\ResponseHeader::remove('X-Powered-By', 'PHP');
-
Retrieving and removing a header at once (with optional value prefix)
$header = \Delight\Http\ResponseHeader::take('Set-Cookie'); // or $header = \Delight\Http\ResponseHeader::take('Set-Cookie', 'mysession=');
All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed.
This project is licensed under the terms of the MIT License.