Home > Article > Backend Development > How to set response headers in php
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.
php set response header
1, set response header file type
<?php header('Content-Type:text/css;charset=GBK');//css文件类型,GBK编码 header('Content-Type:text/html;charset=UTF-8');//html文件类型,UTF-8类型 header('Content-Type:text/plain');//纯文件类型,不会做任何解析 header('Content-Type:applcation/javascript');//javascript文件类型 ?>
2, Redirect (jump to other web pages)
<?php header('Location:https://www.baidu.com');//跳转到百度网页 ?>
3. Download file
<?php header('Content-Type:application/octet-stream');//设置文件下载 header('Content-Disposition:attachment;filename=dome.txt'); ?>
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!