Home  >  Article  >  Backend Development  >  How to set response headers in php

How to set response headers in php

藏色散人
藏色散人Original
2020-07-23 10:34:365302browse

How to set the response header in php: 1. Set the response header file type, with statements such as "header('Content-Type: text/css;charset=GBK');"; 2. Set redirection; 3 , setting file download.

How to set response headers in php

php set response header

1, set response header file type

<?php 
    header(&#39;Content-Type:text/css;charset=GBK&#39;);//css文件类型,GBK编码
    header(&#39;Content-Type:text/html;charset=UTF-8&#39;);//html文件类型,UTF-8类型
    header(&#39;Content-Type:text/plain&#39;);//纯文件类型,不会做任何解析
    header(&#39;Content-Type:applcation/javascript&#39;);//javascript文件类型
?>

2, Redirect (jump to other web pages)

<?php 
    header(&#39;Location:https://www.baidu.com&#39;);//跳转到百度网页
?>

3. Download file

<?php 
    header(&#39;Content-Type:application/octet-stream&#39;);//设置文件下载
    header(&#39;Content-Disposition:attachment;filename=dome.txt&#39;);
?>

Recommended: "PHP Tutorial"

The above is the detailed content of How to set response headers in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn