MENU
HTTP Header
header($s [,$b=true [, $i]]) sends a raw HTTP header as specified by $s. Its call must precede any output, including HTML tags, spaces, and PHP output. $b specifies whether to replace a previous similar header. If $b is FALSE, a second header of the same type will be added. $i specifies the HTTP response code.This forces test.exe to be downloaded as download.exe. Note that this hides the URL of the source.
<?php
// The MIME type
header('Content-type: application/octet-stream');
// The target name
header('Content-Disposition: attachment; filename="download.exe"');
// The source
readfile('test.exe');
?>
This also forces test.exe to be downloaded, but the URL may be shown in a download manager.
<?php
header("Location: test.exe");
?>
<?php
header("Location: http://binarybehemoth.com");
?>
This disables caching at the client's side.
header_remove($s) removes a header previously set using header(). headers_list() returns an array of response headers sent (or ready to be sent). headers_sent([&$s [, &$i]]) returns true if the header block has been sent. No more header lines can be sent using header(), once the headers have been sent. $s stores the PHP source file name while $i stores the line number where output started. header_register_callback($func) registers a function that will be called after PHP prepares all headers to be sent, before any other output is sent, and before any headers are sent. http_presponse_code([$i]) returns or sets the HTTP response code. If $i is provided, the response code will be set; otherwise you will get the response code.
<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 2010 08:00:00 GMT"); // past
?>
This disables caching at the client's side.
<?php
header("Field1: ABC");
header("Field2: DEF");
header("Field3: GHI");
header_remove("Field2");
header_register_callback(callback);
$headers=headers_list();
var_dump(headers_sent());
print_r($headers);
echo http_response_code();
function callback(){
header_remove("Field2");
}
?>
bool(false) Array ( [0] => X-Powered-By: ZendServer 6.3.0 [1] => Field1: ABC [2] => Field3: GHI ) 200