分享PHP header函数使用教程
时间:2023-09-04 12:07:14
<?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';
?>
标签:PHP,header
0
投稿
猜你喜欢
Python中的map、reduce和filter浅析
2021-07-13 23:57:08
vue3 自定义指令控制按钮权限的操作代码
2024-05-09 15:08:59
pycharm 使用anaconda为默认环境的操作
2023-10-08 12:37:25
mysql中的临时表如何使用
2024-01-28 10:19:21
mysql 导入导出数据
2011-02-23 12:27:00
Ranorex通过Python将报告发送到邮箱的方法
2021-08-17 03:57:43
python机器学习混淆矩阵及confusion matrix函数使用
2023-03-08 18:14:12
python源文件的字符编码知识点详解
2021-04-30 08:05:04
如何利用SQL Server 2005中的模板参数
2009-01-23 15:02:00
SQL查询语句求出用户的连续登陆天数
2024-01-17 22:00:40
Pytorch四维Tensor转图片并保存方式(维度顺序调整)
2023-09-11 23:26:54
IE中radio 或checkbox的checked属性初始状态下不能选中显示问题
2024-05-10 14:06:42
IE6局部调用PNG32合并图片
2009-03-11 21:24:00
IE7异常CSS 导致内存破坏漏洞
2009-11-30 12:52:00
Python常用编译器原理及特点解析
2021-09-04 05:10:11
MYSQL开启远程访问权限的方法
2024-01-14 02:17:04
python使用ProjectQ生成量子算法指令集
2023-03-17 20:26:51
关于go语言编码需要放到src 文件夹下的问题
2023-07-03 07:34:00
Python魔法方法 容器部方法详解
2021-02-05 19:25:43
用gpu训练好的神经网络,用tensorflow-cpu跑出错的原因及解决方案
2021-02-11 08:06:31