for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Redaxscript;
/**
* children class to add and remove the header
*
* @since 3.3.0
* @package Redaxscript
* @category Header
* @author Henry Ruhs
*/
class Header
{
* init the class
public static function init()
self::add(
[
'X-Content-Type-Options: nosniff',
'X-Frame-Options: sameorigin',
'X-XSS-Protection: 1; mode=block'
]);
self::remove('X-Powered-By');
}
* add the header
* @param string|array $header
* @param bool $replace
* @return bool
public static function add($header = null, bool $replace = true) : bool
if (!self::isSent())
foreach ((array)$header as $value)
header($value, $replace);
return true;
return false;
* remove the header
public static function remove($header = null) : bool
header_remove($value);
* is header sent
public static function isSent() : bool
return headers_sent();
* get the header array
* @return array
public static function getArray() : array
return headers_list();
* status code
* @param int $code
* @return int
public static function statusCode(int $code = null) : int
return http_response_code($code);
* redirect to location
* @param string $location
public static function doRedirect(string $location = null) : bool
return self::add('Location: ' . $location);
* content type
* @param string $type
public static function contentType(string $type = null) : bool
return self::add('Content-Type: ' . $type);