您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php header 404跳转错误页面实例

2024/2/29 16:01:15发布17次查看
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();
 }
}
如果讲到apache那就简单多了,errordocument 404 /404.html
注意了,如果你写好之后一定要利用专题404错误页面工具进行测试哦,否则可能返回200就不好了,一定要看到是404状态才行。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product