php header功能的使用
更新時間:2013年10月28日 15:46:51 作者:
php header的使用,PHP常見header狀態(tài)總結(jié)。
header() 函數(shù)向客戶端發(fā)送原始的 HTTP 報頭。
復(fù)制代碼 代碼如下:
<?php
//200 正常狀態(tài)
header('HTTP/1.1 200 OK');
// 301 永久重定向,記得在后面要加重定向地址 Location:$url
header('HTTP/1.1 301 Moved Permanently');
// 重定向,其實就是302 暫時重定向
header('Location: http://www.maiyoule.com/');
// 設(shè)置頁面304 沒有修改
header('HTTP/1.1 304 Not Modified');
// 顯示登錄框,
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="登錄信息"');
echo '顯示的信息!';
// 403 禁止訪問
header('HTTP/1.1 403 Forbidden');
// 404 錯誤
header('HTTP/1.1 404 Not Found');
// 500 服務(wù)器錯誤
header('HTTP/1.1 500 Internal Server Error');
// 3秒后重定向指定地址(也就是刷新到新頁面與 <meta http-equiv="refresh" content="10;http://www.fzitv.net/ /> 相同)
header('Refresh: 3; url=http://www.fzitv.net/');
echo '10后跳轉(zhuǎn)到http://www.fzitv.net';
// 重寫 X-Powered-By 值
header('X-Powered-By: PHP/5.3.0');
header('X-Powered-By: Brain/0.6b');
//設(shè)置上下文語言
header('Content-language: en');
// 設(shè)置頁面最后修改時間(多用于防緩存)
$time = time() - 60; //建議使用filetime函數(shù)來設(shè)置頁面緩存時間
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
// 設(shè)置內(nèi)容長度
header('Content-Length: 39344');
// 設(shè)置頭文件類型,可以用于流文件或者文件下載
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
readfile('example.zip');//讀取文件到客戶端
//禁用頁面緩存
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Pragma: no-cache');
//設(shè)置頁面頭信息
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain');
header('Content-Type: image/jpeg');
header('Content-Type: application/zip');
header('Content-Type: application/pdf');
header('Content-Type: audio/mpeg');
header('Content-Type: application/x-shockwave-flash');
//.... 至于Content-Type 的值 可以去查查 w3c 的文檔庫,那里很豐富
?>
您可能感興趣的文章:
- php出現(xiàn)Cannot modify header information問題的解決方法大全
- php header()函數(shù)使用說明
- PHP Header用于頁面跳轉(zhuǎn)要注意的幾個問題總結(jié)
- php利用header函數(shù)實現(xiàn)文件下載時直接提示保存
- php session_start()關(guān)于Cannot send session cache limiter - headers already sent錯誤解決方法
- PHP 頁面編碼聲明方法詳解(header或meta)
- PHP下利用header()函數(shù)設(shè)置瀏覽器緩存的代碼
- php header Content-Type類型小結(jié)
- PHP header()函數(shù)使用詳細(xì)(301、404等錯誤設(shè)置)
- php中g(shù)et_headers函數(shù)的作用及用法的詳細(xì)介紹
- 探討php中header的用法詳解
- PHP 使用header函數(shù)設(shè)置HTTP頭的示例解析 表頭
- 淺析php header 跳轉(zhuǎn)
- php用header函數(shù)實現(xiàn)301跳轉(zhuǎn)代碼實例
- PHP錯誤Warning: Cannot modify header information - headers already sent by解決方法
- PHP使用header()輸出圖片緩存實例
- PHP 常用的header頭部定義匯總
相關(guān)文章
php使用$_POST或$_SESSION[]向js函數(shù)傳參
php向js函數(shù)傳參的方法有多種,可以使用$_POST也可使用$_SESSION[' '],也可用echo語句進(jìn)行輸出,需要的朋友可以參考下2014-09-09
Swoole 4.x服務(wù)器Server配置和函數(shù)列表
Swoole是一個使用C++語言編寫的基于異步事件驅(qū)動和協(xié)程的并行網(wǎng)絡(luò)通信引擎,為PHP提供協(xié)程、高性能網(wǎng)絡(luò)編程支持,使用同步風(fēng)格實現(xiàn)異步程序2024-11-11
本文總結(jié)了Swoole 4.x服務(wù)器預(yù)定義常量、Server配置選項、Server函數(shù)列表、Server屬性列表、事件回調(diào)函數(shù)
php中json_encode不兼容JSON_UNESCAPED_UNICODE的解決方案
本文主要介紹針對PHP5.4以下版本的json_encode不兼容JSON_UNESCAPED_UNICODE的處理,需要的朋友可以參考下。2016-05-05
PHP字符串與數(shù)組處理函數(shù)用法小結(jié)
這篇文章主要介紹了PHP字符串與數(shù)組處理函數(shù)用法,結(jié)合實例形式詳細(xì)分析了PHP字符串與數(shù)組常用處理函數(shù)功能、定義、使用方法與操作注意事項,需要的朋友可以參考下2020-01-01
PHP中date()日期函數(shù)有關(guān)參數(shù)整理
PHP中date()日期函數(shù)有關(guān)參數(shù)整理,需要的朋友可以參考下。2011-07-07
如何使用FireFox插件FirePHP調(diào)試PHP
使用這個工具,首先你需要安裝FirePHP插件。這個插件需要你已經(jīng)安裝FireBug。裝好FirePHP之后,重新打開Firebug面板時候,你會看到新加了一個藍(lán)色的臭蟲圖標(biāo)。點擊這個圖標(biāo)會出現(xiàn)一個開啟或者關(guān)閉FirePHP的菜單2013-07-07
解決163/sohu/sina不能夠收到PHP MAIL函數(shù)發(fā)出郵件的問題
最近準(zhǔn)備改改自己的個人主頁,加上發(fā)郵件到功能,發(fā)現(xiàn)居然不是那么好用。gmail和msn可以收到郵件,但是163/sina/sohu的郵箱居然都收不到,非常郁悶。其實代碼也很簡單。 php manual 已經(jīng)說得相當(dāng)清楚了。2009-03-03

