Monday, April 1, 2013

HTTP Headers

HTTP Headers is used to send a raw HTTP header. It tell the client what data is going to render as html in browser.

Following are the same cases where we use header.


Used to specify that file not found.
header("HTTP/1.0 404 Not Found");

Redirect from current page to another page
header("Location: http://200-530.blogspot.in");

Specify we are going to download a pdf file.
// We'll be outputting a PDF
header('Content-type: application/pdf');

// It will be called downloadfile.pdf
header('Content-Disposition: attachment; filename="downloadfile.pdf"');

// The PDF source is in originalFile.pdf
readfile('originalFile.pdf');

Used to specify, Don't cache a page.
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

No comments:

Post a Comment