开发者

Use of header in PHP

What are some possible uses of the he开发者_开发问答ader function in PHP?

Could someone provide me with some links for reading about this function?

Thank you.


You can do all sorts of things using the header function in PHP. Change page location, set timezone, set caching control, etc.

Here ya go http://php.net/manual/en/function.header.php

Here's a better "applicable use" tutorial as well: http://www.kirupa.com/web/header.htm


The header function sets the headers for an HTTP Response.

From Wikipedia on HTTP Headers:

The header fields define various characteristics of the data transfer that is requested or the data that is provided in the message body. Header fields start with the field name, terminated with a colon character, followed by the field value. Field names and values may be any application-specific strings, but a core set of fields is standardized by the Internet Engineering Task Force (IETF) in RFC 2616 and other updates and extension documents (e.g., RFC 4229), and are commonly understood by all compliant protocol implementations.

There is a lengthy list of both, Request and Response parameters at that article:

  • https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Response_fields

What happens when a client receives an HTTP Response header depends on the individual clients. For instance, when sending

header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');

your browser will likely prompt you with a Login dialogue, whereas sending a

header("HTTP/1.0 404 Not Found");

could tell a Search Engine Spider that it should remove that page from it's index if it previously existed, and so on.

An important datum in Response Headers is the Status code. The Status codes are important for Clients to determine whether a previous Request could be handled by the serving server. You can find a list of Status Codes at

  • http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html


Definitelly visit PHP's section about headers.

for a quicky:

http://www.w3schools.com/php/func_http_header.asp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜