헤더의 몇 가지 사용법

2562 단어
1. 페이지 건너뛰기
header('Location:'.$url);  //Location ":"     。

2. 콘텐츠-type 선언
header('Content-Type: text/html; charset=utf-8'); //    
header('Content-Type: text/plain'); //     
header('Content-Type: image/jpeg'); //JPG、JPEG 
header('Content-Type: application/zip'); // ZIP  
header('Content-Type: application/pdf'); // PDF  
header('Content-Type: audio/mpeg'); //      
header('Content-type: text/css'); //css  
header('Content-type: text/javascript'); //js  
header('Content-type: application/json'); //json
header('Content-type: application/pdf'); //pdf
header('Content-type: text/xml'); //xml
header('Content-Type: application/x-shockw**e-flash'); //Flash  

3. response 상태 코드를 되돌려줍니다
header('HTTP/1.1 200 OK'); // ok     
header('HTTP/1.1 404 Not Found'); //           
header('HTTP/1.1 301 Moved Permanently'); //            301
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); //             
header('HTTP/1.1 304 Not Modified'); //               

4. 일정 시간 후 점프 수행
header('Refresh: 10; url=http://www.baidu.com/'); //             

5. 브라우저 캐시 제어
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . "GMT");
header("Cache-Control: no-cache, must-revalidate"); 
header("Pragma: no-cache");

6. http 검증 실행
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');

7. 다운로드 작업 수행
header('Content-Type: application/octet-stream'); //      
header('Content-Disposition: attachment; filename="example.zip"'); //  MIME      
header('Content-Transfer-Encoding: binary'); //      
header('Content-Length: '.filesize('example.zip')); //      
//          xls  
header('Content-Disposition: attachment; filename=ithhc.xlsx');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Length: '.filesize('./test.xls')); 
header('Content-Transfer-Encoding: binary'); 
header('Cache-Control: must-revalidate'); 
header('Pragma: public'); 
readfile('./test.xls');

좋은 웹페이지 즐겨찾기