先来了解header函数
header() 函数向客户端发送原始的 http 报头,header(string,replace,http_response_code)
php header 404写法:
php代码
代码如下 复制代码
header(http/1.1 404 not found);exit;
如果以上代码不凑效,可以试试以下代码:
php代码
代码如下 复制代码
header(status: 404 not found);
上面只是404状态页面很难看,如果我们要验证需要如下操作
代码如下 复制代码
@header(http/1.1 404 not found);
@header(status: 404 not found);
include(404.html);//跳转到某一个页面,推荐使用这种方法
exit();
这样不但有错误提示信息同时还会有一个漂亮的页面哦,我在实例应用中的一个实例
代码如下 复制代码
function getref()
{
$url = @$_server['http_referer'];
if( !empty( $url ) )
{
if( !strstr($url ,'111cn.net' ) && !strstr($url,'111cn.net'))
{
@header(http/1.1 404 not found);
@header(status: 404 not found);
include(404.html);//跳转到某一个页面,推荐使用这种方法
exit();
}
}
else
{
@header(http/1.1 404 not found);
@header(status: 404 not found);
include(404.html);//跳转到某一个页面,推荐使用这种方法
exit();
}
}
如果讲到apache那就简单多了,errordocument 404 /404.html
注意了,如果你写好之后一定要利用专题404错误页面工具进行测试哦,否则可能返回200就不好了,一定要看到是404状态才行。
