RE: [PHP] header() ???
| From: | Jason Murray | Date: | Thu, 14 Sep 2000 03:35:47 +0000 |
| Subject: | RE: [PHP] header() ??? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-16672@lists.php.net to get a copy of this message | ||
> Sorry that I didn't quite get it :)
>
> What do you mean by any lines or spaces before that will cause an error.
>
> I am confused because usually when we want to display an html page, we can
> just use ---include "filename.php"
> why this time I need to add header().
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