Home > Backend Development > PHP Problem > How to set response headers in php

How to set response headers in php

藏色散人
Release: 2023-03-03 06:10:01
Original
5335 people have browsed it

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文件类型
?>
Copy after login

2, Redirect (jump to other web pages)

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

3. Download file

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template