php设置header参数_php发送get请求

php设置header参数_php发送get请求voidheader(stringstring[,boolreplace[,inthttp_response_code]])voidheader(stringstring[,boolreplace[,inthttp_response_code]])header()是用来发送HTTPHeader的。replace是个可选的参数,指示是否替代一个先期相

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

void header ( string string [, bool replace [, inthttp_response_code]] )
void header ( string string [, bool replace [, inthttp_response_co
de]] )

header()是用来发送 HTTPHeader的。replace是个可选的参数,指示是否替代一个先期相似的header,
或者增加第2个相同类型的header。默认的是替代,但是如果你传递FALSE参数给第2个参数(即replace),你
能强制使用多个相同类型的header。例如:

<?php
header(‘WWW-Authenticate: Negotiate’);
header(‘WWW-Authenticate: NTLM’, false);
?>

第二个可选的参数http_response_code强置HTTP响应代码的值。(PHP>4.3.0)

有两种特定的 header调 用。一种是header用字符串”HTTP/”开头的(大小写无所谓),它用
来指定发出的HTTP状态码。举个例子来说,如果你已经配置 Apache使用javascript:;”on
Click=”javascript:tagshow(event, ‘PHP’);”target=”_self”>PHP脚本来处理请求
不存在的文件(用ErrorDocument指令),你可能想确认你的脚本生成一个合适的状态码:

<?php
header(“HTTP/1.0 404 Not Found”);
?>

注意:HTTP状态行 总是最先发送给客户端的,不管你实际上在什么时候调用header()函数。
除非你的HTTP header已经发送出去了,否则,在任何时候,状态将会被header()函数用一个新的
状态行 覆盖。
在PHP 3中,只有PHP编译为Apache的模块是,并且用下面Staus Header才能取得同样的效果

<?php
header(“Status: 404 Not Found”);
?>

第二中特殊的情况就是”Location:”header。如果没有某些 3xx的状态码已经发出的话,它不仅
发出Location行,而且发出一个重定向的状态码(302)。

<?php
header(“Location: http://www.upsdn.net”);
exit;
?>

注意:HTTP/1.1要求一个绝对 URI作为Location的参数:包括协议头,主机名和绝对路径,
但是某些客户端可以接受相对URI。你可 用$_SERVER[‘HTTP_HOST’]$_SERVER[‘PHP_SELF’]和
dirname()来从一个相对URI来产生绝对 URI。

<?php
header(“Location: http://” . $_SERVER[‘HTTP_HOST’]
. dirname($_SERVER[‘PHP_SELF’])
. “/” . $relative_url);
?>

PHP脚本通常生成一些动态的内容,不必被客户端的浏览器或者代理服务器缓 存。许多代理和客户端可以
强制禁止缓存:

<?php
// 时间总是过去的
header(“Expires: Mon, 26 Jul 1997 05:00:00GMT”);
//文件总是被修改的
header(“Last-Modified: “. gmdate(“D, d M Y H:i:s”) . ” GMT”);

// HTTP/1.1
header(“Cache-Control: no-store, no-cache,must-revalidate”);
header(“Cache-Control: post-check=0, pre-check=0″,false);

// HTTP/1.0
header(“Pragma:no-cache”);
?>

注意:你可能发现即使你没有输出上面的header,你的页面还是不能被 缓存。可能是有几个选项改变了默认的
缓存行为。见sessrion_cache_limiter().

如果你想提示用户保存你发送过去的数据,比如一个已经生成的PDF文件,你可以用Content_Dispostion
头来提供一个推荐的文件名,强迫浏览器显示保存对话框
.

<?php
header(‘Content-type: application/pdf’);
header(‘Content-Disposition: attachment;filename=”downloaded.pdf”‘);
readfile(‘original.pdf’);
?>

对于IE,要加上Connection头

header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: “.$url);
header(“Connection: close”);

header 中Content-type的种类

Content-type 的说明:
‘hqx’ -> ‘application/mac-binhex40’,
‘cpt’ -> ‘application/mac-compactpro’,
‘doc’ -> ‘application/msword’,
‘bin’ -> ‘application/octet-stream’,
‘dms’ -> ‘application/octet-stream’,
‘lha’ -> ‘application/octet-stream’,
‘lzh’ -> ‘application/octet-stream’,
‘exe’ -> ‘application/octet-stream’,
‘class’ -> ‘application/octet-stream’,
‘so’ -> ‘application/octet-stream’,
‘dll’ -> ‘application/octet-stream’,
‘oda’ -> ‘application/oda’,
‘pdf’ -> ‘application/pdf’,
‘ai’ -> ‘application/postscript’,
‘eps’ -> ‘application/postscript’,
‘ps’ -> ‘application/postscript’,
‘smi’ -> ‘application/smil’,
‘smil’ -> ‘application/smil’,
‘mif’ -> ‘application/vnd.mif’,
‘xls’ -> ‘application/vnd.ms-excel’,
‘ppt’ -> ‘application/vnd.ms-powerpoint’,
‘wbxml’ -> ‘application/vnd.wap.wbxml’,
‘wmlc’ -> ‘application/vnd.wap.wmlc’,
‘wmlsc’ -> ‘application/vnd.wap.wmlscriptc’,
‘bcpio’ -> ‘application/x-bcpio’,
‘vcd’ -> ‘application/x-cdlink’,
‘pgn’ -> ‘application/x-chess-pgn’,
‘cpio’ -> ‘application/x-cpio’,
‘csh’ -> ‘application/x-csh’,
‘dcr’ -> ‘application/x-director’,
‘dir’ -> ‘application/x-director’,
‘dxr’ -> ‘application/x-director’,
‘dvi’ -> ‘application/x-dvi’,
‘spl’ -> ‘application/x-futuresplash’,
‘gtar’ -> ‘application/x-gtar’,
‘hdf’ -> ‘application/x-hdf’,
‘js’ -> ‘application/x-javas

cript’,
‘skp’ -> ‘application/x-koan’,
‘skd’ -> ‘application/x-koan’,
‘skt’ -> ‘application/x-koan’,
‘skm’ -> ‘application/x-koan’,
‘latex’ -> ‘application/x-latex’,
‘nc’ -> ‘application/x-netcdf’,
‘cdf’ -> ‘application/x-netcdf’,
‘sh’ -> ‘application/x-sh’,
‘shar’ -> ‘application/x-shar’,
‘swf’ -> ‘application/x-shockwave-flash’,
‘sit’ -> ‘application/x-stuffit’,
‘sv4cpio’ -> ‘application/x-sv4cpio’,
‘sv4crc’ -> ‘application/x-sv4crc’,
‘tar’ -> ‘application/x-tar’,
‘tcl’ -> ‘application/x-tcl’,
‘tex’ -> ‘application/x-tex’,
‘texinfo’ -> ‘application/x-texinfo’,
‘texi’ -> ‘application/x-texinfo’,
‘t’ -> ‘application/x-troff’,
‘tr’ -> ‘application/x-troff’,
‘roff’ -> ‘application/x-troff’,
‘man’ -> ‘application/x-troff-man’,
‘me’ -> ‘application/x-troff-me’,
‘ms’ -> ‘application/x-troff-ms’,
‘ustar’ -> ‘application/x-ustar’,
‘src’ -> ‘application/x-wais-source’,
‘xhtml’ ‘application/xhtml+xml’,
‘xht’ -> ‘application/xhtml+xml’,
‘zip’ -> ‘application/zip’,
‘au’ -> ‘audio/basic’,
‘snd’ -> ‘audio/basic’,
‘mid’ -> ‘audio/midi’,
‘midi’ -> ‘audio/midi’,
‘kar’ -> ‘audio/midi’,
‘mpga’ -> ‘audio/mpeg’,
‘mp2’ -> ‘audio/mpeg’,
‘mp3’ -> ‘audio/mpeg’,
‘aif’ -> ‘audio/x-aiff’,
‘aiff’ -> ‘audio/x-aiff’,
‘aifc’ -> ‘audio/x-aiff’,
‘m3u’ -> ‘audio/x-mpegurl’,
‘ram’ -> ‘audio/x-pn-realaudio’,
‘rm’ -> ‘audio/x-pn-realaudio’,
‘rpm’ -> ‘audio/x-pn-realaudio-plugin’,
‘ra’ -> ‘audio/x-realaudio’,
‘wav’ -> ‘audio/x-wav’,
‘pdb’ -> ‘chemical/x-pdb’,
‘xyz’ -> ‘chemical/x-xyz’,
‘bmp’ -> ‘image/bmp’,
‘gif’ -> ‘image/gif’,
‘ief’ -> ‘image/ief’,
‘jpeg’ -> ‘image/jpeg’,
‘jpg’ -> ‘image/jpeg’,
‘jpe’ -> ‘image/jpeg’,
‘png’ -> ‘image/png’,
‘tiff’ -> ‘image/tiff’,
‘tif’ -> ‘image/tiff’,
‘djvu’ -> ‘image/vnd.djvu’,
‘djv’ -> ‘image/vnd.djvu’,
‘wbmp’ -> ‘image/vnd.wap.wbmp’,
‘ras’ -> ‘image/x-cmu-raster’,
‘pnm’ -> ‘image/x-portable-anymap’,
‘pbm’ -> ‘image/x-portable-bitmap’,
‘pgm’ -> ‘image/x-portable-graymap’,
‘ppm’ -> ‘image/x-portable-pixmap’,
‘rgb’ -> ‘image/x-rgb’,
‘xbm’ -> ‘image/x-xbitmap’,
‘xpm’ -> ‘image/x-xpixmap’,
‘xwd’ -> ‘image/x-xwindowdump’,
‘igs’ -> ‘model/iges’,
‘iges’ -> ‘model/iges’,
‘msh’ -> ‘model/mesh’,
‘mesh’ -> ‘model/mesh’,
‘silo’ -> ‘model/mesh’,
‘wrl’ -> ‘model/vrml’,
‘vrml’ -> ‘model/vrml’,
‘css’ -> ‘text/css’,
‘html’ -> ‘text/html’,
‘htm’ -> ‘text/html’,
‘asc’ -> ‘text/plain’,
‘txt’ -> ‘text/plain’,
‘rtx’ -> ‘text/richtext’,
‘rtf’ -> ‘text/rtf’,
‘sgml’ -> ‘text/sgml’,
‘sgm’ -> ‘text/sgml’,
‘tsv’ -> ‘text/tab-separated-values’,
‘wml’ -> ‘text/vnd.wap.wml’,
‘wmls’ -> ‘text/vnd.wap.wmlscript’,
‘etx’ -> ‘text/x-setext’,
‘xsl’ -> ‘text/xml’,
‘xml’ -> ‘text/xml’,
‘mpeg’ -> ‘video/mpeg’,
‘mpg’ -> ‘video/mpeg’,
‘mpe’ -> ‘video/mpeg’,
‘qt’ -> ‘video/quicktime’,
‘mov’ -> ‘video/quicktime’,
‘mxu’ -> ‘video/vnd.mpegurl’,
‘avi’ -> ‘video/x-msvideo’,
‘movie’ -> ‘video/x-sgi-movie’,
‘ice’ -> ‘x-conference/x-cooltalk’

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/172675.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • pycharm怎么设置字体和颜色_pycharm背景颜色

    pycharm怎么设置字体和颜色_pycharm背景颜色个人使用记录:1.settings-Appearance–勾选Overridedefaultfonts.设置字体和大小如下:(点击Apply应用)2.Editor-Font-选择主题Shame(需要SaveAs…才可以修改,个人喜欢黑色底,选了个浅黑色),设置字体和大小3.保存,应用后,查看自己面板中显示是否合意(嗯,是我喜欢的样子~)…

  • 协调世界时utc_utc协调世界时什么意思

    协调世界时utc_utc协调世界时什么意思协调世界时UTC:又称世界标准时间或世界协调时间,简称UTC(从英文“CoordinatedUniversalTime”/法文“TempsUniverselCordonné”而来

  • Mybatis中JdbcType的使用[通俗易懂]

    Mybatis中JdbcType的使用[通俗易懂]MyBatis插入空值时,需要指定JdbcTypemybatisinsert空值报空值异常,但是在PL/SQL不会提示错误,主要原因是mybatis无法进行转换jdbcType的使用场合,只有当在insert,update和delete中有空字段时,需要使用jdbcType。MyBatis包含的jdbcType类型BIT、FLOAT、CHAR、TIMESTAMP、OTHE…

    2022年10月20日
  • 360常用快捷键_10个常用的快捷键

    360常用快捷键_10个常用的快捷键“工欲善其事必先利其器”,整理了一份360常用快捷键。======================================常用快捷键======================================Ctrl+小键盘“+”当前页面放大10%Ctrl+小键盘“-”当前页面缩小10%——————-…

  • ubuntu nginx安装配置_PHP开发环境搭建步骤

    ubuntu nginx安装配置_PHP开发环境搭建步骤一、说明正在尝试基于nginx+php搭建web服务器,中途遇到不少问题。挣扎了三四个小时终于完成了,这里分享下经验。实验环境操作系统:Ubuntu18.0464位nginx:1.14.0php:7.2.17-0php-fram:php7.2-fpm二、实验步骤1、安装必要程序以及依赖#安装程序包sudoapt-getinstallphp7.2…

  • SpringBoot跨域设置(CORS)「建议收藏」

    SpringBoot跨域设置(CORS)「建议收藏」目录什么是跨域跨域资源共享(CORS)1.简单请求2.非简单请求SpringBoot设置CORS1.配置过滤器CorsFilter2.实现接口WebMvcConfigurer3.使用注解@CrossOrigin什么是跨域请求url的协议、域名、端口三者有任意一个不同即为跨域。跨域问题是因为浏览器的同源策略的限制而产生的。同源:请求url的协议、域名、端口三者都相同即为同源(同一个域)。同源策略:同源策略(Sameoriginpolicy)是一种约定,他是浏览器最核心也最基本的安全

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号