php header示例代码(推荐)

代码如下:

<?php
/*** Function: PHP header() examples (PHP)
** Desc: Some examples on how to use the header() function of PHPYou find a detailed tutorial at expertsrt.com (English) or at ffm.junetz.de (German).These is also a good help about caching at web-caching.com.
** Example: see below. <br/><br/><b>Tip:</b> You can use these sites to check your headers: <a href="http://web-sniffer.net/">web-sniffer.net</a>, <a href="http://www.delorie.com/web/headers.html">delorie.com</a> or <a href="http://www.forret.com/projects/analyze/">www.forret.com</a>.
** Author: Jonas John
*/

// 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';
?>

(0)

相关推荐

  • php 模拟get_headers函数的代码示例

    复制代码 代码如下: <?php 02 if(!function_exists('get_headers')){ 03     function get_headers($url,$format=0){ 04         $url=parse_url($url); 05         $end="\r\n\r\n"; 06         $fp=fsockopen($url['host'],(empty($url['port'])?80:$url['port']),$er

  • 分享PHP header函数使用教程

    复制代码 代码如下: <?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'); // redirec

  • PHP header函数分析详解

    在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

  • php header 详细使用说明与使用心得第1/2页

    不管页面有多少header,它会执行最后一个,不过是有条件的,例如: header('Location:http://www.jb51.net'); header('Location:http://www.g.cn'); header('Location:http://www.baidu.com'); 这个就会跳到百度 header('Location:http://www.jb51.net');echo '我们'; header('Location:http://www.g.cn'); hea

  • 探讨php中header的用法详解

     header() is used to send raw HTTP headers. See the HTTP/1.1 specification for more information on HTTP headers. 范例一: 复制代码 代码如下: <?PHPHeader("Location: http://www.jb51.net";); exit;//在每个重定向之后都必须加上"exit",避免发生错误后,继续执行.?> 复制代码 代码如下:

  • php header示例代码(推荐)

    复制代码 代码如下: <?php /*** Function: PHP header() examples (PHP) ** Desc: Some examples on how to use the header() function of PHPYou find a detailed tutorial at expertsrt.com (English) or at ffm.junetz.de (German).These is also a good help about caching

  • Java servlet 使用 PrintWriter 时的编码与乱码的示例代码

    在前面的网页中的编码与乱码系列中,曾多次提到使用 servlet 方式构建的动态响应流,不过在那里都是直接使用字节流的方式,不过,更为常见的方式是使用字符流.而在前面,又谈到了 Java 字节流与字符流的话题. 有了前面的基础,现在来说下 Java servlet 中使用字符流,也即是 PrintWriter 时的编码与乱码问题. 回顾字节流的情形 先回顾一下,在之前的字节流响应中,我们使用 String.getBytes 方法,然后总是显式传入编码的参数,使它与 meta 中或者 header

  • PHP Pipeline 实现中间件的示例代码

    Pipeline 设计模式 水管太长,只要有一处破了,就会漏水了,而且不利于复杂环境弯曲转折使用.所以我们都会把水管分成很短的一节一节管道,然后最大化的让管道大小作用不同,因地制宜,组装在一起,满足各种各样的不同需求. 由此得出 Pipeline 的设计模式,就是将复杂冗长的流程 (processes) 截成各个小流程,小任务.每个最小量化的任务就可以复用,通过组装不同的小任务,构成复杂多样的流程 (processes). 最后将「输入」引入管道,根据每个小任务对输入进行操作 (加工.过滤),最

  • golang之JWT实现的示例代码

    什么是JSON Web Token? JSON Web Token(JWT)是一个开放标准(RFC 7519),它定义了一种紧凑且自包含的方式,用于在各方之间以JSON方式安全地传输信息.由于此信息是经过数字签名的,因此可以被验证和信任.可以使用秘密(使用HMAC算法)或使用RSA或ECDSA的公钥/私钥对对JWT进行签名. 直白的讲jwt就是一种用户认证(区别于session.cookie)的解决方案. 出现的背景 众所周知,在jwt出现之前,我们已经有session.cookie来解决用户登

  • C#调用HTTP POST请求上传图片的示例代码

    现在很多B/S系统的开发都是通过API方式来进行的,一般服务端会开放一个API接口,客户端调用API接口来实现图片或文件上传的功能. GET和POST是什么?HTTP协议中的两种发送请求的方法. HTTP是什么?HTTP是基于TCP/IP的关于数据如何在万维网中如何通信的协议. HTTP的底层是TCP/IP.所以GET和POST的底层也是TCP/IP,也就是说,GET/POST都是TCP链接.GET和POST能做的事情是一样一样的.你要给GET加上request body,给POST带上url参

  • node.js实现身份认证的示例代码

    请问昨天结束的早是对堆积在了今天吗,今天还来加个班更博,看在这个毅力的份上能否给亿点点推荐. 有个好消息有个坏消息,先说坏消息吧,就是在这么学下去我急需急支糖浆,来回顾回顾前面的知识,这几天学的太急了,搞得有点推着走的意思,好消息就是今天的内容是最后最后node的基础内容了,果然天不负我,整完然后有两个大案例,做完我就从上次复习那里开始一直复习过来,然后全部不欠账,就昂首挺胸的走进vue了,等等,这个学完可以进去了吧. 1.今天的第一个内容说一下web开发模式,今天基本就是讲一个身份认证的内容,

  • 利用Go语言实现流量回放工具的示例代码

    目录 前言 goreplay介绍与安装 使用示例 流量放大.缩小 流量写入到ElastichSearch goreplay基本实现原理 总结 前言 哈喽,大家好,我是asong. 今天给大家推荐一款使用Go语言编写的流量回放工具 -- goreplay:工作中你一定遇到过需要在服务器上抓包的场景,有了这个工具就可以助你一臂之力,goreplay的功能十分强大,支持流量的放大.缩小,并且集成了ElasticSearch,将流量存入ES进行实时分析: 废话不多,我们接下来来看一看这个工具: gore

  • jQuery通过ajax请求php遍历json数组到table中的代码(推荐)

    html代码(test.html),js在html底部 具体代码如下所示: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>test-jquery-ajax-list</title> </head> <body> <div class="main">

  • vue 运用mock数据的示例代码

    本文介绍了vue 运用mock数据的示例代码,分享给大家,具体如下: 初始化你的项目 话不用啰嗦,首先初始化你的项目,最简单的就是使用vue-cli啦 vue init webpack 引入mock.js 安装 mockjs npm install --save-dev mockjs 引入到Vue原型上,方便使用 import mockjs from 'mockjs' Vue.prototype.$mock = Vue.$mock = mockjs.mock 以上引入到Vue原型上,可以使用 t

  • AngularJs bootstrap详解及示例代码

    AngularJs学习笔记系列第一篇,希望我可以坚持写下去.本文内容主要来自 http://docs.angularjs.org/guide/ 文档的内容,但也加入些许自己的理解与尝试结果. 一.总括 本文用于解释Angular初始化的过程,以及如何在你有需要的时候对Angular进行手工初始化. 二.Angular <script> 标签 本例用于展示如何通过推荐的路径整合Angular,实现自动初始化. <!doctype html> <html xmlns:ng=&qu

随机推荐