PHP header函数是用来向浏览器等user agent发放http头信息的函数,header函数必须放在任何输出之前,如果在PHP header函数之前已经有了输出,那么请使用ob_start()函数

header(“HTTP/1.1 404 Not Found”);
header(“HTTP/1.1 404″);

2、PHP header函数永久重定向
header(“Location:”); //默认是301 跳转
// 临时重定向
header(“HTTP/1.1 302 Found”);

3、PHP header函数下载文件
header(“Content-type: text/plain”); //可以替换成你需要的MIME类型
header(‘Content-Disposition: attachment; filename=”xx.txt”‘);

其他的头信息可以参考HTTP/1.1 specification


  1. Thank you sharing most of these wonderful posts. In addition, the optimal travel along with medical insurance approach can often reduce those concerns that come with touring abroad. Your medical crisis can rapidly become very costly and that’s likely to quickly decide to put a financial load on the family’s finances. Having in place the perfect travel insurance program prior to setting off is definitely worth the time and effort. Cheers

  2. Well, this really is my very first visit to your site! We are a small grouping of volunteers and starting a new motivation in a local community in the same niche. Your site provided all of us valuable information to work about. You have done a new marvellous job!


电子邮件地址不会被公开。 必填项已用*标注

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>