header命令学习笔记

注意: 传统的标头一定包含下面三种标头之一,并只能出现一次。

    * Content-Type: xxxx/yyyy
    * Location: xxxx:yyyy/zzzz
    * Status: nnn xxxxxx

范例一: 本例用来重导用户到 PHP 的官方网站。
Header("Location: http://www.php.net");  exit;

范例二: 欲让用户每次都能得到最新的资料,而不是 Proxy 或 cache 中的资料,可以使用下列的标头
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");

范例三: 让用户的浏览器出现找不到文件的信息。
header("Status: 404 Not Found");

范例四: 提供让用户下载文件的范例。
header("Content-type: application/x-gzip");
header("Content-Disposition: attachment; filename=some-file.tar.gz");
header("Content-Description: PHP3 Generated Data");

其它:
header("Content-type:text/gif;");
header("Content-Type: text/html; charset=gb2312");
header("Content-type: text/xml");

PHP header常用指令

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'); 
 
// 显示登录对话框,可以用来进行HTTP认证
// 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';

 

 <style type="text/css" > </style>

<style type="text/javascript" > </style>
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值