两個有用的 php header 讯息

字体大小: 中小 标准 ->行高大小: 标准
一般上在 php 里使用 header() 函式是网页转向,現提供一個较好的转向及另一个实用技巧:

301 转向
google 建议当网站转换网址時使用 301 转向,用 php 实现 301 转向可用以下语法:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/page.htm");
exit();
?>

404 错误页面
一般上用 GET 传入变数给 php 程式显示不同內容,但总有一些用戶会修改 GET 变数后的字串看会发生什么事,很多人也会显示错误讯息或什么也沒有便算,其实可以透过 header() 发送 404 错误讯息:
<?php
header("HTTP/1.0 404 Not Found");
header("Status: 404 Not Found");
exit;
?> 

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/691.html