PHP header()函数常用方法总结

前端之家收集整理的这篇文章主要介绍了PHP header()函数常用方法总结前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

//定义编码
<div class="codetitle"><a style="CURSOR: pointer" data="35940" class="copybut" id="copybut35940" onclick="doCopy('code35940')"> 代码如下:

<div class="codebody" id="code35940">header( 'Content-Type:text/html;charset=utf-8 ');

//Atom
<div class="codetitle"><a style="CURSOR: pointer" data="27654" class="copybut" id="copybut27654" onclick="doCopy('code27654')"> 代码如下:
<div class="codebody" id="code27654">header('Content-type: application/atom+xml');

//CSS
<div class="codetitle"><a style="CURSOR: pointer" data="5627" class="copybut" id="copybut5627" onclick="doCopy('code5627')"> 代码如下:
<div class="codebody" id="code5627">header('Content-type: text/css');

//Javascript
<div class="codetitle"><a style="CURSOR: pointer" data="45148" class="copybut" id="copybut45148" onclick="doCopy('code45148')"> 代码如下:
<div class="codebody" id="code45148">header('Content-type: text/javascript');
//JPEG Image
<div class="codetitle"><a style="CURSOR: pointer" data="26586" class="copybut" id="copybut26586" onclick="doCopy('code26586')"> 代码如下:<div class="codebody" id="code26586">header('Content-type: image/jpeg');
//JSON
<div class="codetitle"><a style="CURSOR: pointer" data="8832" class="copybut" id="copybut8832" onclick="doCopy('code8832')"> 代码如下:<div class="codebody" id="code8832">header('Content-type: application/json');
//PDF
<div class="codetitle"><a style="CURSOR: pointer" data="35535" class="copybut" id="copybut35535" onclick="doCopy('code35535')"> 代码如下:<div class="codebody" id="code35535">header('Content-type: application/pdf');
//RSS
<div class="codetitle"><a style="CURSOR: pointer" data="55425" class="copybut" id="copybut55425" onclick="doCopy('code55425')"> 代码如下:<div class="codebody" id="code55425">header('Content-Type: application/RSS+xml; charset=ISO-8859-1');
//Text (Plain)
<div class="codetitle"><a style="CURSOR: pointer" data="22313" class="copybut" id="copybut22313" onclick="doCopy('code22313')"> 代码如下:<div class="codebody" id="code22313">header('Content-type: text/plain');
//XML
<div class="codetitle"><a style="CURSOR: pointer" data="21649" class="copybut" id="copybut21649" onclick="doCopy('code21649')"> 代码如下:<div class="codebody" id="code21649">header('Content-type: text/xml');
// ok
<div class="codetitle"><a style="CURSOR: pointer" data="97082" class="copybut" id="copybut97082" onclick="doCopy('code97082')"> 代码如下:<div class="codebody" id="code97082">header('HTTP/1.1 200 OK');
//设置一个404头:
<div class="codetitle"><a style="CURSOR: pointer" data="70784" class="copybut" id="copybut70784" onclick="doCopy('code70784')"> 代码如下:<div class="codebody" id="code70784">header('HTTP/1.1 404 Not Found');
//设置地址被永久的重定向
<div class="codetitle"><a style="CURSOR: pointer" data="23122" class="copybut" id="copybut23122" onclick="doCopy('code23122')"> 代码如下:<div class="codebody" id="code23122">header('HTTP/1.1 301 Moved Permanently');
//转到一个新地址
<div class="codetitle"><a style="CURSOR: pointer" data="66107" class="copybut" id="copybut66107" onclick="doCopy('code66107')"> 代码如下:<div class="codebody" id="code66107">header('Location: http://www.example.org/');
//文件延迟转向:
<div class="codetitle"><a style="CURSOR: pointer" data="90269" class="copybut" id="copybut90269" onclick="doCopy('code90269')"> 代码如下:<div class="codebody" id="code90269">header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
//当然,也可以使用html语法实现
// <meta http-equiv="refresh" content="10;http://www.example.org/ />
// override X-Powered-By: PHP:
<div class="codetitle"><a style="CURSOR: pointer" data="17781" class="copybut" id="copybut17781" onclick="doCopy('code17781')"> 代码如下:<div class="codebody" id="code17781">header('X-Powered-By: PHP/4.4.0');
header('X-Powered-By: Brain/0.6b');
//文档语言
<div class="codetitle"><a style="CURSOR: pointer" data="82129" class="copybut" id="copybut82129" onclick="doCopy('code82129')"> 代码如下:<div class="codebody" id="code82129">header('Content-language: en');
//告诉浏览器最后一次修改时间
<div class="codetitle"><a style="CURSOR: pointer" data="15645" class="copybut" id="copybut15645" onclick="doCopy('code15645')"> 代码如下:<div class="codebody" id="code15645">$time = time() - 60; // or filemtime($fn),etc
header('Last-Modified: '.gmdate('D,d M Y H:i:s',$time).' GMT');
//告诉浏览器文档内容没有发生改变
<div class="codetitle"><a style="CURSOR: pointer" data="88537" class="copybut" id="copybut88537" onclick="doCopy('code88537')"> 代码如下:<div class="codebody" id="code88537">header('HTTP/1.1 304 Not Modified');
//设置内容长度
<div class="codetitle"><a style="CURSOR: pointer" data="96419" class="copybut" id="copybut96419" onclick="doCopy('code96419')"> 代码如下:<div class="codebody" id="code96419">header('Content-Length: 1234');
//设置为一个下载类型
<div class="codetitle"><a style="CURSOR: pointer" data="46217" class="copybut" id="copybut46217" onclick="doCopy('code46217')"> 代码如下:<div class="codebody" id="code46217">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');
// 对当前文档禁用缓存
<div class="codetitle"><a style="CURSOR: pointer" data="23381" class="copybut" id="copybut23381" onclick="doCopy('code23381')"> 代码如下:<div class="codebody" id="code23381">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 past
header('Pragma: no-cache');
//设置内容类型:
<div class="codetitle"><a style="CURSOR: pointer" data="18445" class="copybut" id="copybut18445" onclick="doCopy('code18445')"> 代码如下:<div class="codebody" id="code18445">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'); //JPG*
header('Content-Type: application/zip'); // ZIP文件
header('Content-Type: application/pdf'); // PDF文件
header('Content-Type: audio/mpeg'); // 音频文件
header('Content-Type: application/x-shockw
e-flash'); //Flash动画
//显示登陆对话框
<div class="codetitle"><a style="CURSOR: pointer" data="6696" class="copybut" id="copybut6696" onclick="doCopy('code6696')"> 代码如下:<div class="codebody" id="code6696">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';

原文链接:https://www.f2er.com/php/24817.html

猜你在找的PHP相关文章