How to clear http header in php

藏色散人
Release: 2023-03-11 12:16:01
Original
2338 people have browsed it

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
Copy after login

(PHP 5 >= 5.3.0, PHP 7)

header_remove — Delete the previously set HTTP header

Description

header_remove ([ string $name ] ) : void
Copy after login

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"); 
?>
Copy after login

The output of the above routine is similar to:

X-Bar: Baz
Copy after login

Example #2 Cancel all previously specified headers Header

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

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template