php8.5
Home/ Manual/ network / functions/ header_remove

header_remove

PHP function Edit on GitHub ✎

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

Remove previously set headers

Description

header_remove(string|null $name = null): void

Removes an HTTP header previously set using header().

Parameters

name

The header name to be removed. When null, all previously set headers are removed.

Note

This parameter is case-insensitive.

Return Values

Void

Changelog

VersionDescription
8.0.0name is nullable now.

Examples

Unsetting specific header.

php
<?php
header("X-Foo: Bar");
header("X-Bar: Baz");
header_remove("X-Foo"); 
?>

The above example will output something similar to:

output
X-Bar: Baz

Unsetting all previously set headers.

php
<?php
header("X-Foo: Bar");
header("X-Bar: Baz");
header_remove(); 
?>

The above example will output something similar to:

output

Notes

Caution

This function will remove all headers set by PHP, including cookies, session and the X-Powered-By headers.

Sapi

See Also

Source: reference/network/functions/header-remove.xml · from the official PHP manual (php/doc-en)