![]() |
header() function, can anyone explain
I'm seeing a lot of the header() function.
Can anyone tell me what exactly are raw-headers and how do they work? Thanks a lot. |
When the server returns the page that the client requests, it also attaches along hidden information that the browser uses (but doesn't necessarily let you see).
The header information can be used to tell your browser to use the cached page, it can be used to raise a 404 (missing page), a 505 (server error), it's used to tell the browser what server the site is running on. It can also be used to differentiate data from html (Content-type: text/html) and an image (Content-type: image/jpeg). Or even trigger file downloads (Content-type: application/x-download). This is all part of what makes up the Hyper Text Transfer Protocal (HTTP). Basically, it's what helps your browser interpret precisely what the server wants you to see. With use of the header() function in PHP, you can modify the raw header by simply putting the information in to the funtion call. Without use of the header() function, the default header information is used according to the PHP default settings. So doing something like "header('Content-type: image/jpeg')", will modify the default content-type attribute to the newly specified format. For further understanding, here's an example of a PHP download script. It has some undeclared variables, but it's simple to work in to something usable. :
$stream = fopen($fname, 'rb'); |
header() can also be used for silent redirection
:
|
Thanks a lot guys.
|
Sane: application/x-download is silly. It doesn't tell the browser what the file really is, so it can't decide what to do with it (like open in an external application).
|
I thought if you don't have that, and only have "Content-Disposition" declared, it only works on half of the browsers.
|
http://us3.php.net/manual/en/function.header.php
gives a lot of information on it. |
| All times are GMT -5. The time now is 12:50 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC