PHP 网络函数

PHP header_remove() 函数用于删除之前使用 header() 函数响应的标头。

语法

header_remove(name) 

    参数

    name可选。 指定要删除的标头名称。当为空时,所有先前设置的标头都将被删除。请注意,这是一个不区分大小写的参数。

    返回值

    不返回任何值。

    示例:删除特定标头

    在下面的示例中,header_remove()函数用于删除特定标头。

    <?php
    header("Expires: Mon, 14 Oct 2019 10:30:00 GMT");
    header("Cache-Control: no-cache");
    header("Pragma: no-cache");
    
    //删除"Pragma"标头
    header_remove("Pragma"); 
    ?> 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    上述代码的标头输出将类似于:

    Expires: Mon, 14 Oct 2019 10:30:00 GMT
    Cache-Control: no-cache 
    • 1

    示例:删除所有先前设置的标头

    再考虑一个示例,其中此函数用于删除所有先前设置的标头。

    <?php
    header("Expires: Mon, 14 Oct 2019 10:30:00 GMT");
    header("Cache-Control: no-cache");
    header("Pragma: no-cache");
    
    //没有参数,删除所有标头
    header_remove(); 
    ?> 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    上述代码的输出将是: