PHP中常用的请求头代码

设置常用的content-type:

//定义编码
header( ‘Content-Type:text/html;charset=utf-8 ‘);

//Atom
header(‘Content-type: application/atom+xml‘);

//CSS
header(‘Content-type: text/css‘);

//Javascript
header(‘Content-type: text/javascript‘);

//JPEG Image
header(‘Content-type: image/jpeg‘);

//JSON
header(‘Content-type: application/json‘);

//PDF
header(‘Content-type: application/pdf‘);

//RSS
header(‘Content-Type: application/rss+xml; charset=ISO-8859-1‘);

//Text (Plain)
header(‘Content-type: text/plain‘);

//XML
header(‘Content-type: text/xml‘);

// 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.example.org/‘);

//文件延迟转向:
header(‘Refresh: 10; url=http://www.example.org/‘);
print ‘You will be redirected in 10 seconds‘;

//当然,也可以使用html语法实现
// <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‘);

//文档语言
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-revalidate‘);
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-shockw**e-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‘;

时间: 2024-08-29 03:24:49

PHP中常用的请求头代码的相关文章

Http消息头中常用的请求头和响应头

作为Web开发对常用http的请求头和响应头熟悉了解一下还是很有必要的.比如请求头中Content-type指定了请求的内容,若类型是application/x-www-form-urlencoded,就可以调用reqeust的获取参数方法取到内容,若是其它都需要调用获取流的方法获取.又比如响应头X-Frame-Options 的设置直接决定了你的页面是否能被其它非同源的ifream嵌入,而这个设置可以是在html页面中,也可以是框架或代码的响应头设置中,也可以是在http服务器(nginx或t

linux 中常用的一些头文件

#include <linux/***.h> 是在linux-2.6.29/include/linux下面寻找源文件. #include <asm/***.h> 是在linux-2.6.29/arch/arm/include/asm下面寻找源文件. #include <mach/***.h> 是在linux-2.6.29/arch/arm/mach-s3c2410/include/mach下面寻找源文件. #include <plat/regs-adc.h>

PHP中检测ajax请求的代码例子

多数情况下,基于JavaScript 的Js框架如jquery.Mootools.Prototype等,在发出Ajax请求指令时,都会发送额外的 HTTP_X_REQUESTED_WITH 头部信息,就当是一个ajax请求,因此你可以在服务器端检测到这些Ajax请求,在PHP中的检测方法如下代码所示: <?php if(!emptyempty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUE

nginx常用的请求头参数和防DDOS攻击

前端squid反向代理到nginx nginx根据http_user_agent防DDOS 首先查看访问日志,找出可疑访问 找到http_user_agent 的特征,然后再作过滤 "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0; MyIE 3.01)Cache-Control: no-store, must-revalidate" if ($http_user_agent ~ must-revalidate) { return

wordpress中常用的一些php代码

<?php the_author(); ?> 显示文章的作者 <?php the_author_description(); ?> 显示文章作者的描述(作者个人资料中的描述) <?php the_author_login(); ?> 显示文章作者的登录名 <?php the_author_firstname(); ?> 显示文章作者的firstname(名) <?php the_author_lastname(); ?> 显示文章作者的lastn

SAP中常用SM系列事务代码总结

SM01 锁定事物 SM02 系统信息 SM04 显示在线用户 SM12 删除,显示锁对象 SM13 看update  request SM21 看下系统日志 SM30|SM31 维护table|view数据 SM32 维护表 SM35 进程监护 SM36 定义后台job SM37 查看后台job SM39 作业分析 SM49 执行外部OS命令

请求头的设置

<常用的请求头> "content-type":'application/x-www-form-urlencoded;charset=utf-8' "content-type":'multipart/form-data' 表单提交值写在encType中 <form encType="application/x-www-form-urlencoded;"> content-type对照表 <ajax上传文件> v

HTTP协议中常用状态码和含义,以及错误信息提示

转自:https://www.cnblogs.com/williamjie/p/9849996.html   https://www.cnblogs.com/omak/p/10211449.html HTTP协议状态码,是指在HTTP协议运作中由客户端发出请求连接,服务端建立连接,客户端发出HTTP请求,服务端返回响应信息,而在这个过程张由于客户端或服务端的问题会返回相应的错误代码并显示给用户,对应的错误代码表示不同的错误信息,根据这个信息用户可以调整相应的操作来修改出现的错误,最终避免错误的再

设置请求头解决浏览器同源问题

思想: 添加过滤器 设置请求头 代码如下 package com.deppon.vas.common.framework.cors; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servl