1. 跳轉(zhuǎn)頁(yè)面
header('Location:'.$url); //Location和":"之間無(wú)空格忍级。
2. 聲明content-type
header('Content-Type: text/html; charset=utf-8'); //網(wǎng)頁(yè)編碼
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動(dòng)畫(huà)
3. 返回response狀態(tài)碼
header('HTTP/1.1 200 OK'); // ok 正常訪問(wèn)
header('HTTP/1.1 404 Not Found'); //通知瀏覽器 頁(yè)面不存在
header('HTTP/1.1 301 Moved Permanently'); //設(shè)置地址被永久的重定向 301
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT'); //告訴瀏覽器最后一次修改時(shí)間
header('HTTP/1.1 304 Not Modified'); //告訴瀏覽器文檔內(nèi)容沒(méi)有發(fā)生改變
4. 在某個(gè)時(shí)間后執(zhí)行跳轉(zhuǎn)
header('Refresh: 10; url=http://www.baidu.com/'); //延遲轉(zhuǎn)向 也就是隔幾秒跳轉(zhuǎn)
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. 執(zhí)行http驗(yàn)證
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
7. 執(zhí)行下載操作
header('Content-Type: application/octet-stream'); //設(shè)置內(nèi)容類(lèi)型
header('Content-Disposition: attachment; filename="example.zip"'); //設(shè)置MIME用戶(hù)作為附件
header('Content-Transfer-Encoding: binary'); //設(shè)置傳輸方式
header('Content-Length: '.filesize('example.zip')); //設(shè)置內(nèi)容長(zhǎng)度
// 聲明一個(gè)需要下載的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');
最后編輯于 :2017.12.09 01:33:18
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者