本文分享几个php header函数的例子,有需要的朋友参考学习下。

1,可以使用heder命令,强制使浏览器使用新鲜的内容(无缓存) 。
也可以给网址增加了一个唯一的编号,使其每次都读取新的内容,避免缓存。
例子:

复制代码代码示例:

<? print“<img src=’yourfile.jpg’>”;   //通常读取的是缓存文件
?> 
<?
print“<img src=’yourfile.jpg?”.time().“‘>”;   //增加了唯一的编号,使浏览器重新请求

w//print“<img src=’yourfile.jpg?”.rand(100,999).“‘>”;
?>

2,自定义php函数,将图片传送给浏览器显示。

复制代码代码示例:
<?php
function PE_img_by_path($PE_imgpath = “”)
{
    if (file_exists($PE_imgpath)) {
        $PE_imgarray = pathinfo($PE_imgpath); 
        $iconcontent = file_get_contents($PE_imgpath);
        header(“Content-type: image/” . $PE_imgarray["extension"]);
        header(‘Content-length: ‘ . strlen($iconcontent));
        echo $iconcontent;
        die(0);
    }
    return false;
}
?>

更多实例:

复制代码代码示例:
<?php 
// ok
header(‘HTTP/1.1 200 OK’); 
//设置一个404头:
header(‘HTTP/1.1 404 Not Found’); 
//设置地址被永久的重定向
header(‘HTTP/1.1 301 Moved Permanently’); 
//转到一个新地址
header(‘Location: http://www.jbxue.com/’); 
//文件延迟转向:
header(‘Refresh: 10; url=http://www.jbxue.com/’);
print ‘You will be redirected in 10 seconds’; 
//当然,也可以使用html语法实现
// <meta http-equiv=”refresh” content=”10;http://www.jbxue.com/ /> 
// override X-Powered-By: PHP:
header(‘X-Powered-By: PHP/4.4.0′);
header(‘X-Powered-By: Brain/0.6b’); 
//文档语言
header(‘Content-language: en’); 
//告诉浏览器最后一次修改时间
$time = time() – 60; // or filemtime($fn), etc
header(‘Last-Modified: ‘.gmdate(‘D, d M Y H:i:s’, $time).’ GMT’); 
//告诉浏览器文档内容没有发生改变
header(‘HTTP/1.1 304 Not Modified’); 
//设置内容长度
header(‘Content-Length: 1234′); 
//设置为一个下载类型
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’); 
// 对当前文档禁用缓存
header(‘Cache-Control: no-cache, no-store, max-age=0, must-ridate’);
header(‘Expires: Mon, 26 Jul 1997 05:00:00 GMT’); // Date in the past
header(‘Pragma: no-cache’); 
//设置内容类型:
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-shockwave-flash’); //Flash动画 
//显示登陆对话框
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’;
?>

header的更多相关文章

  1. RestTemplate发送请求并携带header信息

    1.使用restTemplate的postForObject方法 注:目前没有发现发送携带header信息的getForObject方法. HttpHeaders headers = new Http ...

  2. ABP Zero示例项目登录报错“Empty or invalid anti forgery header token.”问题解决

    ABP Zero项目,登录时出现如图"Empty or invalid anti forgery header token."错误提示的解决方法: 在 WebModule.cs的P ...

  3. ASP.NET MVC 3 网站优化总结(三)Specify Vary: Accept-Encoding header

    继续进行 ASP.NET MVC 3 网站优化工作,使用 Google Page 检测发现提示 You should Specify Vary: Accept-Encoding header,The ...

  4. .htaccess添加Header set Cache-Control报错500

    在优化网站开启站点的图片缓存时,需要在.htaccess文件中加入: #文件缓存时间配置10分钟 <FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf ...

  5. 如何实现可动态调整隐藏header的listview

    (转自:http://blog.sina.com.cn/s/blog_70b9730f01014sgm.html) 需求:根据某种需要,可能需要动态调整listview的页眉页脚,譬如将header作 ...

  6. PHP header函数设置http报文头(设置头部域)

    PHP HTTP 简介: HTTP 函数允许您在其他输出被发送之前,对由 Web 服务器发送到浏览器的信息进行操作. PHP 5 HTTP 函数:header()     向客户端发送原始的 HTTP ...

  7. 【HTML5&CSS3进阶学习02】Header的实现·CSS中的布局

    前言 我们在手机上布局一般是这个样子的: 其中头部对整个mobile的设计至关重要,而且坑也很多: ① 一般来说整个header是以fixed布局,fixed这个产物在移动端来说本身坑就非常多 ② 在 ...

  8. webservice客户端添加soap Header信息

    根据wsdl文件的header信息,在客户端中添加相应的header 1.wsdl信息如图 <soapenv:Envelope xmlns:soapenv="http://schema ...

  9. HTTP Header 详解

    HTTP(HyperTextTransferProtocol)即超文本传输协议,目前网页传输的的通用协议.HTTP协议采用了请求/响应模型,浏览器或其他客户端发出请求,服务器给与响应.就整个网络资源传 ...

  10. java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called.

    分析:android 4.2.X及以下的版本,addHeaderView必须在setAdapter之前,否则会抛出IllegalStateException. android 4.2.X(API 17 ...

随机推荐

  1. Android studio .gitignore 文件的内容

    # built application files *.apk *.ap_ # files for the dex VM *.dex # Intellij project files .idea/ . ...

  2. [IOS]edgesForExtendedLayout、automaticallyAdjustsScrollViewInsets

    在IOS7以后 ViewController 开始使用全屏布局的,而且是默认的行为通常涉及到布局 就离不开这个属性 edgesForExtendedLayout,它是一个类型为UIExtendedEd ...

  3. android am命令以及hotkey文件的编写

    1.拨打电话:am start -a android.intent.action.CALL -d tel:10086 这里-a表示动作,-d表述传入的数据,还有-t表示传入的类型. 2. 打开一个网页 ...

  4. iOS开发-生成随机数

    有时候我们需要在程序中生成随机数,但是在Objective-c中并没有提供相应的函数,好在C中提供了rand().srand().random().arc4random()几个函数.那么怎么使用呢?下 ...

  5. SQLite3的基本使用

    |SQLite3简介  SQLite3只是一个轻型的嵌入式数据库引擎,占用资源非常低,处理速度比Mysql还快,专门用于移动设备上进行适量的数据存取,它只是一个文件,不需要服务器进程. 常用术语:表( ...

  6. 如何开启win7端口的图文教程

    Windows 7/Vista/XP/2003等系统中的远程终端服务是一项功能非常强大的服务,下面来教教大家如何开启端口:打开“控制面板”中的“Windows防火墙”,点击左侧的“高级设置” 右击“入 ...

  7. 转载文章----C#基础概念

    转载地址:http://www.cnblogs.com/zhouzhou-aspnet/articles/2591596.html 1.值类型和引用类型 1.1堆和栈 简单的说值类型存放在堆栈上面,引 ...

  8. 试用 Nexus OSS 3.0 的docker仓库 (二)

    试用 Nexus OSS 3.0 的docker仓库 (一) : http://www.cnblogs.com/wzy5223/p/5410990.html 三. 创建docker私有仓库,docke ...

  9. 【JSP】JSP基础学习记录(一)—— 基础介绍以及3个编译指令

    序: 从实现到现在一直是以.net为主,但偶尔也会参与一些其他语言的项目.最近需要对一个Java Web项目进行二次开发,一直没学习过JSP所以买了几本书自学试试.参考资料为<轻量级Java E ...

  10. SQL查询数据库中所有指定类型的字段名称和所在的表名

    --查询数据库中所有指定类型的字段名称和所在的表名 --eg: 下面查的是当前数据库中 所有字段类型为 nvarchar(max) 的字段名和表名 SELECT cols.object_id , co ...