note 25999 deleted from function.header by sniper
| From: | sniper@php.net | Date: | Sun, 07 Sep 2003 21:34:46 +0000 |
| Subject: | note 25999 deleted from function.header by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55621@lists.php.net to get a copy of this message | ||
Note Submitter:
----
header("Status: 404 Not Found");
The second special case is the "Location:" header. Not only does it send this header back
to the browser, but it also returns a REDIRECT (302) status code to the browser unless some 3xx
status code has already been set.
header("Location: http://www.example.com/");
/* Redirect browser */
exit; /* Make sure that code below does
not get executed when we redirect. */
Note: HTTP/1.1 requires an absolute URI as argument to Location: including the scheme, hostname and
absolute path, but some clients accept relative URIs. You can usually use
$_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute
URI from a relative one yourself:
header("Location: http://".$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
."/".$relative_url);
PHP scripts often generate dynamic content that must not be cached by the client browser or any
proxy caches between the server and the client browser. Many proxies and clients can be forced to
disable caching with
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
Note: You may find that your pages aren't cached even if you don't output all of the
headers above. There are a number of options that users may be able to set for their browser that
change its default caching behavior. By sending the headers above, you should override any settings
that may otherwise cause the output of your script to be cached.
Additionally, session_cache_limiter() and the session.cache_limiter configuration setting can be
used to automatically generate the correct caching-related headers when sessions are being used.
Remember that header() must be called before any actual output is sent, either by normal HTML tags,
blank lines in a file, or from PHP. It is a very common error to read code with include(), or
require(), functions, or another file access function, and have spaces or empty lines that are
output before header() is called. The same problem exists when using a single PHP/HTML file.
<?php header ("Content-type: audio/x-pn-realaudio"); ?>
// Broken, note the blank line above
Note: In PHP 4, you can use output buffering