Home  >  Article  >  Backend Development  >  How to clear http header in php

How to clear http header in php

藏色散人
藏色散人Original
2021-07-10 09:49:552298browse

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().

How to clear http header in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn