php header 404 跳转错误页面实例
404 页面是一种友好的错误提示页面,在 php 中我们可以利用 php,apache,hatcess 三种
方法来实现向浏览器发送
404 错误页面状态,下面我来介绍其它的 php header 函数实现 404
错误页面的具体方法。
先来了解
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();