2009年12月2日星期三

两个有用的 PHP header

在 php 里使用 header() 函数是网页转向,現提供一個较好的转向及另一个实用技巧:

301 转向
google 建议当网站转换网址時使用 301 转向,用 php 实现 301 转向可用以下语法:
[php]
header("http/1.1 301 moved permanently");
header("location: http://www.livingelsewhere.net");
exit();
[/php]

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

没有评论 :

发表评论