Skip to content

A simple way to read headers from the `getallheaders` function in PHP.

License

Notifications You must be signed in to change notification settings

nabeghe/headers-reader-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Headers Reader for PHP

A simple way to read headers from the getallheaders function in PHP.


🫡 Usage

🚀 Installation

You can install the package via composer:

composer require nabeghe/headers-reader

Example 1 - Main Class

use Nabeghe\HeadersReader\Headers;

echo 'X-Custom-1: '.Headers::get('X-Custom-1', 'The default value for X-Custom-1')."\n<br>";
echo 'X-Custom-2: '.Headers::get('X-Custom-2', 'The default value for X-Custom-2')."\n<br>";
echo 'X-Custom-3: '.Headers::get('X-Custom-3', 'The default value for X-Custom-3')."\n<br>";
echo 'X-Custom-4: '.Headers::get('X-Custom-4', 'The default value for X-Custom-4')."\n<br>";
echo 'X-Custom-5: '.Headers::get('X-Custom-4')."\n<br><br>"; // Default value is blank.

print_r(Headers::all()); // Returns all headers.

Headers::flush(); // Clears the cache.

Example 1 - Custom Class

use Nabeghe\HeadersReader\Headers;

class MyHeaders extends Headers
{
    public const DEFAULT = 'The general default value';

    public const DEFAULTS = [
        'X-Custom-1' => 'The default value for X-Custom-1',
        'X-Custom-2' => 'The default value for X-Custom-2',
        'X-Custom-3' => 'The default value for X-Custom-3',
        'X-Custom-4' => 'The default value for X-Custom-4',
    ];
}

echo 'X-Custom-1: '.MyHeaders::get('X-Custom-1')."\n<br>";
echo 'X-Custom-2: '.MyHeaders::get('X-Custom-2')."\n<br>";
echo 'X-Custom-3: '.MyHeaders::get('X-Custom-3')."\n<br>";
echo 'X-Custom-4: '.MyHeaders::get('X-Custom-4')."\n<br>";
echo 'X-Custom-5: '.MyHeaders::get('X-Custom-5')."\n<br>";

📖 License

Copyright (c) Hadi Akbarzadeh

Licensed under the MIT license, see LICENSE.md for details.