PHP supports realization of the mechanism of sending of headings HTTP.
First we shall say some words about http headings.
According to the specification http, this report supports transfer of the service information from the server to a browser, made out as special headings.
Thus, http headers is means of dialogue of the server with the removed client. Each heading will usually consist of a single line ascii the text with a name and value. Headings are not displayed in any way in a window of a browser, but frequently can change display of the accompanying document strongly.
The mechanism of sending http headings in php.
The mechanism of sending of headings in php is submitted by function header (). Feature of the report http consists that the heading should be sent up to a parcel{sending} of other data, therefore function should be called right at the beginning of the document and should look as follows:
header (" http heading ", unessential parameter replace);
Opcional`nyj the parameter replace can accept values such as bool (true or false) and specifies, whether the previous heading of similar type should be replaced, or add the given heading to already existing.
Concerning function header () function headers_sent () which as result returns true in case of successful sending heading and false in a return case often is applied.
Let's consider the most used http headings.
cache-control.
" cache-control: " value
Heading of management keshirovaniem pages. In general, the given function is one of the headings most widespread in use.
The given heading can be used with the following values:
no-cashe - the Interdiction keshirovanija. It is used in often updated pages and pages with the dynamic maintenance{contents}. It dejsvtie it is similar meta tegu " pragma: no-cache ".
public - the Sanction keshirovanija pages both the local client, and a proxy.
private - the Sanction keshirovanija only the local client.
max-age - the Sanction of use keshirovannogo the document during set time in seconds.
header (" cache-control: private, max-age = 3600 ")/* Keshirovanie local clients and use within 1 hour */
expires.
" expires: " http-date
Establishes date and time after which the document is considered out-of-date. Date should be specified in the following format (in English):
Day of week (JA«¬U). Number (2 figures) Month (JA«¬U). Year chasy:minuty:sekundy gmt
For example, fri, 09 jan 2002 12:00:00 gmt
Current time in this format is returned with function gmdate () in the following kind:
echo gmdate (" d, d m y h:i:s "). "gmt";
Use given http heading for an interdiction keshirovanija is possible. For this purpose it is necessary to name past date.
last-modified.
" last-modified: " http-date
Names date of last change of the document. Date should be set in the same format, as in a case with heading expires. The given heading can be not used for dynamic pages, as many servers (for example, apache) for such pages expose date of updating.
It is possible to make page always updated:
header (" last-modified: " .gmdate (" d, d m y h:i:s "). "gmt");
location.
" location: " absolute url
Useful heading, which perenapravljaet a browser on the specified address. His action is comparable with meta tegom refresh:
<meta http-equiv = "refresh" content = " 0; url=someurl ">
For example, this heading can be used so:
if ($login! = $admin_login) header (" location: http: // www.server.com/login.php ");
else header (" location: http: // www.server.com/admin.php? login = $ login ");
if (! headers_sent ()) exit (" there Was a mistake! Pass <a href ='http: // www.server.com/login.php '> authorization </a> anew ");
We have disassembled certainly not all http headings (on it some lessons will not suffice us), but have considered the most useful and the most used.

|