header() 函數向客戶端發送原始的 HTTP 報頭。
注意:該函數防止一次發送多個報頭。這是對頭部注入攻擊的保護措施。
1.跳轉
header('Location: http://www.example.com/');
2.保存
excel文件
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename=test.xlsx');
header('Cache-Control: max-age=0');
pdf文件
header("Content-type:application/pdf");
// 文件將被稱為 downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'");
// PDF 源在 original.pdf 中
readfile("original.pdf");