PHP header() Funksie
Voorbeeld
Stuur drie HTTP-opskrifte om bladsykas te voorkom:
<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>
<html>
<body>
...
...
Let wel: Daar is opsies wat gebruikers kan stel om die blaaier se verstekkasinstellings te verander. Deur die opskrifte hierbo te stuur, sal jy enige van daardie instellings ignoreer en die blaaier dwing om nie te kas nie!
Definisie en gebruik
Die header()-funksie stuur 'n rou HTTP-kopskrif na 'n kliënt.
Dit is belangrik om daarop te let dat die header() funksie opgeroep moet word voordat enige werklike uitvoer gestuur word!
Sintaksis
header(header, replace, http_response_code)
Parameterwaardes
Parameter | Description |
---|---|
header | Required. Specifies the header string to send |
replace | Optional. Indicates whether the header should replace a previous similar header or add a new header of the same type. Default is TRUE (will replace). FALSE allows multiple headers of the same type |
http_response_code | Optional. Forces the HTTP response code to the specified value |
Tegniese besonderhede
Terugkeerwaarde: | Niks nie |
---|---|
PHP weergawe: | 4,0+ |
PHP Changelog: | PHP 5.1.2: Verhoed nou dat meer as een kop op een slag gestuur word. Dit is 'n beskerming teen kopinspuitingsaanvalle |
Meer voorbeelde
Voorbeeld
Laat die gebruiker gevra word om 'n gegenereerde PDF-lêer te stoor (Content-Disposition-kopskrif word gebruik om 'n aanbevole lêernaam te verskaf en die blaaier te dwing om die stoor-dialoogkassie te vertoon):
<?php
header("Content-type:application/pdf");
// It will be called downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'");
// The PDF source is in original.pdf
readfile("original.pdf");
?>
<html>
<body>
...
...
❮ PHP-netwerkverwysing