![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2006
Posts: 16
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Banned
![]() ![]() |
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');
$contents = fread($stream, filesize($fname));
fclose($stream);
header('Content-Type: application/x-download');
header('Content-Disposition: attachment; filename="'.$fname.'"');
echo $contents;Last edited by Sane; Aug 8th, 2006 at 2:27 PM. |
|
|
|
|
|
#3 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
header() can also be used for silent redirection
php Syntax (Toggle Plain Text)
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Apr 2006
Posts: 16
Rep Power: 0
![]() |
Thanks a lot guys.
|
|
|
|
|
|
#5 |
|
Unverified User
Join Date: Aug 2005
Location: none
Posts: 146
Rep Power: 0
![]() |
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).
__________________
Warning: My posts may change (dramatically) within the first 15 minutes they're posted. Got 'Nux?—GNU/Linux and other free software support. It's GNU/Linux, not just Linux. |
|
|
|
|
|
#6 |
|
Banned
![]() ![]() |
I thought if you don't have that, and only have "Content-Disposition" declared, it only works on half of the browsers.
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Sep 2006
Posts: 2
Rep Power: 0
![]() |
http://us3.php.net/manual/en/function.header.php
gives a lot of information on it. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compiling Maverik 6.2 (from C) | megamind5005 | C | 16 | May 3rd, 2006 6:41 PM |
| libraries | matko | C | 1 | Jan 22nd, 2006 3:12 PM |
| Php Postgresql Class | Pizentios | Show Off Your Open Source Projects | 15 | Jun 28th, 2005 10:55 AM |
| Jackpot game | zorin | Visual Basic | 3 | Jun 10th, 2005 2:19 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 5:12 PM |