RE: [PHP] header() ???
| From: | Sonia Tsui | Date: | Thu, 14 Sep 2000 02:46:40 +0000 |
| Subject: | RE: [PHP] header() ??? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-16678@lists.php.net to get a copy of this message | ||
Jason,
Very good explanation, thanks!
Could you please give me a case under which header() need to be used?
thanks
---Sonia
---------------------------------------
A normal HTTP response from a server looks like this:
[HEADERS]
[blank line]
[DATA - HTML, usually]
Once your PHP script has output anything via echo or print, you can no
longer
issue a header (look at the structure and you'll see, web page data cannot
include headers because it comes after it).
You should use a header if you need to specify a content type or anything
that
is unusual about a page. You can also use it to redirect. The catch is that
it
MUST be used before your PHP outputs anything. It's also handy to use an
Exit()
call after it, or else the script will continue to execute (bad).
Redirection example:
Header("Location: http://www.yahoo.com/");
You can see the headers a server sends by using telnet and entering a manual
HTTP GET commnd as such:
[jason@webdev]$ telnet www.yahoo.com 80
Trying 216.32.74.51...
Connected to www.yahoo.akadns.net.
Escape character is '^]'.
GET / HTTP/1.0
HTTP/1.0 200 OK
Content-Length: 16077
Content-Type: text/html
[[[[ insert actual html of the page here ]]]]
Jason