怎么在PHP中利用header函数设置HTTP头-创新互联

这篇文章将为大家详细讲解有关怎么在PHP中利用header函数设置HTTP头,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

成都创新互联专注于安泽网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供安泽营销型网站建设,安泽网站制作、安泽网页设计、安泽网站官网定制、微信小程序开发服务,打造安泽网络公司原创品牌,更为您提供安泽网站排名全网营销落地服务。

php有什么用

php是一个嵌套的缩写名称,是英文超级文本预处理语言,它的语法混合了C、Java、Perl以及php自创新的语法,主要用来做网站开发,许多小型网站都用php开发,因为php是开源的,从而使得php经久不衰。

如下所示:


//定义编码
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: /tupian/20230522/'); 

//文件延迟转向:
header('Refresh: 10; url=/tupian/20230522/'); 
print 'You will be redirected in 10 seconds'; 

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


关于怎么在PHP中利用header函数设置HTTP头就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


网页名称:怎么在PHP中利用header函数设置HTTP头-创新互联
网页网址:http://pwwzsj.com/article/dsdjdj.html