在php语言中,header()这个函数很有用的,尤其在用到ajax时候,他会帮你解决一些意想不到的问题。下面是header的一些详细讲解。希望对phper有帮助

代码如下:

<?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函数使用教程的更多相关文章

  1. php header()函数设置页面Cache缓存

    header()函数在php的使用很大,下面我来介绍利用它实现页面缓存的一些方法,但使用header前必须注意,在它之前不能任何输出,包括空格. 手册上,我们对于cache都是写着如何设置,以便让代码 ...

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

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

  3. PHP中的header()函数作用

    PHP 中 header()函数的作用是给客户端发送头信息. 什么是头信息?这里只作简单解释,详细的自己看http协议.在 HTTP协议中,服务器端的回答(response)内容包括两部分:头信息(h ...

  4. PHP header函数使用大全

    PHP header函数大全 header('Content-Type: text/html; charset=utf-8'); header('Location: http://52php.cnbl ...

  5. python迭代器与iter()函数实例教程

    python迭代器与iter()函数实例教程 发布时间:2014-07-16编辑:脚本学堂 本文介绍了python迭代器与iter()函数的用法,Python 的迭代无缝地支持序列对象,而且它还允许程 ...

  6. PHP header函数的几大作用

    先看看官方文档的定义 (PHP 4, PHP 5, PHP 7) header - 发送原生 HTTP 头 void header ( string $string [, bool $replace ...

  7. PHP中header函数的用法及其注意重点是什么呢

    1.使用header函数进行跳转页面: header('Location:'.$url); 其中$url就是将要跳转的url了. 这种用法的注意事项有以下几点: •Location和":&q ...

  8. PHP header()函数

    对header函数,我用得最多的就是跳转页面和设置字符集,其他的功能用得比较少. 一.设置字符集 其实我们用的最多的在在html代码当中的<meta>标签里面设置字符集.格式如下: < ...

  9. PHP header() 函数详细说明(301、404等错误设置)

    原文来自:http://www.veryhuo.com/a/view/41466.html 如果您刚刚开始学习PHP,可能有许多函数需要研究,今天我们就来学习一下PHP Header()的使用方法,更 ...

随机推荐

  1. 重装系统分区时,发现一个叫LVM的东西,找出来和大家分享

    LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制,它由Heinz Mauelshagen在Linux 2.4内核上实现,目前 ...

  2. windows8.1+centos7双系统(装完centos后无win8引导)

    原先系统为windows8.1后来装上centos7后无win8系统引导, 打开电脑进入引导界面按C 进入grub界面  输入“cat (hd0,” 按tab可查看到windows8 地址为“hd0, ...

  3. <COM原理和应用>第七章的ITextObject代码是什么?

      第7章中有如下的描述:-----------------------------------为了在程序中使用"Text.Object"文本对象,我们利用ClassWizard引 ...

  4. I/O阻塞非阻塞,同步异步

    http://www.cnblogs.com/luotianshuai/p/5098408.html "阻塞"与"非阻塞"与"同步"与&qu ...

  5. html如何绑定radio控件和label控件

    只要指定label的"for"属性到radio的id就行,或者用label标签包围住radio. 第一种方式: <input type="radio" i ...

  6. 从Unity引擎过度到Unreal4引擎(最终版)

    原文地址:http://demo.netfoucs.com/u011707076/article/details/44036839 前言 寒假回家到现在已经有十多天了,这些天回家不是睡就是吃....哎 ...

  7. UBUNTU9.10下安装TFTP学习笔记一(arm学习SEED-138板子)

    擦,刚刚写的没保存都丢了,郁闷中~~~~ 简单重写 1什么是TFTP .安装TFTP(TFTP(Trivial File Transfer Protocol,简单文件传输协议)是TCP/IP协议族中的 ...

  8. WebForm 简单控件、复合控件

    简单控件: Label:被编译成span 样式表里设置lable的高度:  display:inline-block; Text  --文本 ForeColor  --字体颜色 Visible  -- ...

  9. visual studio installer制作安装包——Installer 类

    链接:https://msdn.microsoft.com/zh-cn/library/system.configuration.install.installer.aspx Installer 类 ...

  10. delphi对象赋值

     Delphi的对象之间赋值主要要注意几个方面的问题:   1.对象之间的 :=赋值只是地址赋值,即是将当前对象的地址赋值到变量中,定义的变量可以是不用初始化的,在内存中两个变量指向的是同一地址空间: ...