两個有用的 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;
?>


申明:本区内容收集自网络,如有署名问题请速与我们(luokelong#it168.com)联系,感谢您的支持。
7上一页  下一页8

制作:罗可龙 电邮:luokelong(at)it168.com