在php中,可以使用header()函数来设置content-type(内容类型),该函数可以向客户端发送原始的HTTP报头,语法“header('Content-type: 类型值');”。

本教程操作环境:windows7系统、PHP7.1版,DELL G3电脑
Content-Type(内容类型),一般是指网页中存在的 Content-Type,用于定义网络文件的类型和网页的编码,决定浏览器将以什么形式、什么编码读取这个文件,这就是经常看到一些 PHP 网页点击的结果却是下载一个文件或一张图片的原因。
Content-Type 标头告诉客户端实际返回的内容的内容类型。
在PHP中,可以通过header()函数来发送头信息,还可以设置文件的content-type,下面整理了一些常见文件类型对于的content-type值。
js自定义设置日期时间倒计时代码,通过使用原生js实现人时间日期的倒计时效果,一般在商城中用的比较多,例如搞某某活动,实现大促销活动,然后一个炫酷的倒计时效果,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: http://www.example.org/');
//文件延迟转向:
header('Refresh: 10; url=http://www.example.org/');
print 'You will be redirected in 10 seconds';
//当然,也可以使用html语法实现
// 推荐学习:《PHP视频教程》










