分享PHP header函數(shù)使用教程
更新時(shí)間:2013年09月05日 15:50:23 作者:
在php語(yǔ)言中,header()這個(gè)函數(shù)很有用的,尤其在用到ajax時(shí)候,他會(huì)幫你解決一些意想不到的問(wèn)題。下面是header的一些詳細(xì)講解。希望對(duì)phper有幫助
復(fù)制代碼 代碼如下:
<?php
// fix 404 pages:
header('HTTP/1.1 200 OK');
// set 404 header:
header('HTTP/1.1 404 Not Found');
// set Moved Permanently header (good for redrictions)
// use with location header
header('HTTP/1.1 301 Moved Permanently');
// redirect to a new location:
header('Location: http://www.example.org/');
// redrict with delay:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
// you could also use the HTML syntax:// <meta http-equiv="refresh" content="10;http://www.example.org/ />
// override X-Powered-By: PHP:
header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');
// content language (en = English)
header('Content-language: en');
// last modified (good for caching)
$time = time() – 60; // or filemtime($fn), etc
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
// header for telling the browser that the content
// did not get changed
header('HTTP/1.1 304 Not Modified');
// set content length (good for caching):
header('Content-Length: 1234');
// Headers for an download:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="example.zip"');
header('Content-Transfer-Encoding: binary');
// load the file to send:readfile('example.zip');
// Disable caching of the current document:
header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
// Date in the pastheader('Pragma: no-cache');
// set content type:
header('Content-Type: text/html; charset=iso-8859-1');
header('Content-Type: text/html; charset=utf-8');
header('Content-Type: text/plain');
// plain text file
header('Content-Type: image/jpeg');
// JPG picture
header('Content-Type: application/zip');
// ZIP file
header('Content-Type: application/pdf');
// PDF file
header('Content-Type: audio/mpeg');
// Audio MPEG (MP3,…) file
header('Content-Type: application/x-shockwave-flash');
// Flash animation// show sign in box
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Top Secret"');
print 'Text that will be displayed if the user hits cancel or ';
print 'enters wrong login data';
?>
相關(guān)文章
有道搜索和IP138的IP的API接口(PHP應(yīng)用)
原理就是通過(guò)php模擬瀏覽器獲取ip地址歸屬地,需要的朋友可以參考下2012-11-11PHP網(wǎng)頁(yè)游戲?qū)W習(xí)之Xnova(ogame)源碼解讀(十)
這篇文章主要介紹了PHP網(wǎng)頁(yè)游戲Xnova(ogame)源碼解讀的建造總覽部分,需要的朋友可以參考下2014-06-06微信公眾平臺(tái)實(shí)現(xiàn)獲取用戶(hù)OpenID的方法
這篇文章主要介紹了微信公眾平臺(tái)實(shí)現(xiàn)獲取用戶(hù)OpenID的方法,需要開(kāi)發(fā)人員經(jīng)過(guò)微信授權(quán)后獲取高級(jí)接口才能使用此功能,用戶(hù)OpenID對(duì)于微信公眾平臺(tái)建設(shè)有著非常廣泛的用途,需要的朋友可以參考下2015-04-04PHP驗(yàn)證碼語(yǔ)言包預(yù)警信息通知總結(jié)示例
這篇文章主要為大家介紹了PHP驗(yàn)證碼語(yǔ)言包預(yù)警信息通知總結(jié)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08淺談php fopen下載遠(yuǎn)程文件的函數(shù)
下面小編就為大家?guī)?lái)一篇淺談php fopen下載遠(yuǎn)程文件的函數(shù)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-11-11Laravel模型間關(guān)系設(shè)置分表的方法示例
這篇文章主要給大家介紹了關(guān)于Laravel模型間關(guān)系設(shè)置分表的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-04-04PHP實(shí)現(xiàn)文件上傳后臺(tái)處理腳本
這篇文章主要為大家詳細(xì)介紹了PHP實(shí)現(xiàn)文件上傳后臺(tái)處理腳本,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-03-03