PHP

[PHP] header()

똑똑한 영장류 2012. 12. 12. 18:03


php를 이용해서 HTTP Raw header 를 전송할 수 있는 함수입니다.



void header ( string $string [, bool $replace = true [, int $http_response_code ]] )



<?php
header
("HTTP/1.0 404 Not Found");
?>


<?php
header
("Location: http://www.example.com/"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>


전송하는 파일을 다운로드받도록 하는 헤더 조작 방법입니다.


<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');

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

// The PDF source is in original.pdf
readfile('original.pdf');
?> 


아래는 캐슁 컨트롤입니다.


<?php
header
("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?> 


모두 테스트 한번씩 해봐야겠군요..