HTTP Headers

HTTP (HyperText Transfer Protocol) is the technology at the heart of the World Wide Web because it defines the way clients and servers can communicate (in layman’s terms). When a browser requests a Web page, it receives a series of HTTP headers in return.

PHP’s built-in function header() can be used to take advantage of this protocol. The most common example of this will be demonstrated here, when the header() function will be used to redirect the Web browser from the current page to another. However, in Chapter 10, “Extended Topics,” you’ll see how to use header() to affect page caching, and in Chapter 8, “Security,” you’ll use it to perform HTTP authentication.

To use header() to redirect the Web browser, type

 header ("Location: ...

Get PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.