Home >Backend Development >PHP Problem >How to clear http header in php
In PHP, you can clear the http header through the header_remove function. The syntax is "header_remove ([ string $name ] ) : void", which means to delete the HTTP header previously set with header().
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How to clear the http header in php?
header_remove
(PHP 5 >= 5.3.0, PHP 7)
header_remove — Delete the previously set HTTP header
Description
header_remove ([ string $name ] ) : void
Delete the HTTP header previously set with header().
Parameters
name
The name of the header to be removed.
Note: Parameters are not case sensitive.
Return value
No return value.
Example
Example #1 Cancel the specified header
<?php header("X-Foo: Bar"); header("X-Bar: Baz"); header_remove("X-Foo"); ?>
The output of the above routine is similar to:
X-Bar: Baz
Example #2 Cancel all previously specified headers Header
<?php header("X-Foo: Bar"); header("X-Bar: Baz"); header_remove(); ?>
Note:
Caution
This function will delete all headers set by PHP, including Cookie, Session and X-Powered-By.
Note:
The data header will only be processed and output when supported by SAPI.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to clear http header in php. For more information, please follow other related articles on the PHP Chinese website!