国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

PHP header 函數(shù)的用法及其注意事項(xiàng)

瀏覽:93日期:2022-09-12 14:17:21
void header ( string $string [, bool $replace = true [, int $http_response_code ]] ) : Send a raw HTTP header下面有一些使用header的幾種用法:1、使用header函數(shù)進(jìn)行跳轉(zhuǎn)頁面;header(’Location:’.$url);其中$url就是將要跳轉(zhuǎn)的url了。這種用法的注意事項(xiàng)有以下幾點(diǎn): Location和':'之間不能有空格,否則會(huì)出現(xiàn)錯(cuò)誤(注釋:我剛測試了,在我本地環(huán)境下,沒有跳轉(zhuǎn)頁面,但是也沒有報(bào)錯(cuò),不清楚什么原因);在用header前不能有任何的輸出(注釋:這點(diǎn)大家都知道的,如果header之前有任何的輸出,包括空白,就會(huì)出現(xiàn)header already sent by xxx的錯(cuò)誤);header 后面的東西還會(huì)執(zhí)行的;2、使用header聲明content-typeheader(’content-type:text/html;charset=utf-8’);這個(gè)沒有什么好說的;3、使用header返回response 狀態(tài)碼header(sprintf(’%s %d %s’, $http_version, $status_code, $description));樣式就是這樣的;例如:header(’HTTP/1.1 404 Not Found’);4、使用header在某個(gè)時(shí)間后執(zhí)行跳轉(zhuǎn)header('Refresh: {$delay}; url={$url}');其中$delay就是推遲跳轉(zhuǎn)的時(shí)間,$url為需要跳轉(zhuǎn)的url例如:header(’Refresh: 10; url=http://www.example.org/’); 意思為10s后跳轉(zhuǎn)到http://www.eexample.org這個(gè)網(wǎng)站5、使用header控制瀏覽器緩存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、使用header進(jìn)行下載操作header(’Content-Type: application/octet-stream’);//設(shè)置內(nèi)容類型header(’Content-Disposition: attachment; filename='example.zip'’); //設(shè)置MIME用戶作為附件下載 如果將attachment換成inline意思為在線打開header(’Content-Transfer-Encoding: binary’);//設(shè)置傳輸方式header(’Content-Length: ’.filesize(’example.zip’));//設(shè)置內(nèi)容長度// load the file to send:readfile(’example.zip’);//讀取需要下載的文件基本上就是上面這些 。。。
標(biāo)簽: PHP
相關(guān)文章:
主站蜘蛛池模板: 潍坊市| 安多县| 崇礼县| 河源市| 东平县| 察哈| 松潘县| 古浪县| 堆龙德庆县| 河源市| 邯郸县| 枣庄市| 绵竹市| 嘉义县| 永吉县| 米林县| 河东区| 行唐县| 博湖县| 正宁县| 麟游县| 乃东县| 清新县| 宁晋县| 芷江| 同仁县| 麦盖提县| 南雄市| 海南省| 曲沃县| 喀喇沁旗| 辛集市| 六安市| 文昌市| 林周县| 康平县| 武夷山市| 绥滨县| 怀集县| 开平市| 新郑市|