php如何返回错误代码

发布时间:2021-09-14 17:14:33 作者:小新
来源:亿速云 阅读:306

这篇文章主要介绍php如何返回错误代码,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

1、用header()函数是可以为返回页面添加404的头信息的。

2、提示浏览器该网页找不到了。

所以可以使用:

header("HTTP/1.0 404 Not Found");

或者:

header("Status: 404 Not Found");

后者是在FastCGI模式下使用的,在php代码中可以把两句直接同时写上。

header使用说明如下:

The header string.There are two special-case header calls. The first is a header that starts with the string "HTTP/" (case is not significant), which will be used to figure out the HTTP status code to send. For example, if you have configured Apache to use a PHP script to handle requests for missing files (using the ErrorDocument directive), you may want to make sure that your script generates the proper status code.For FastCGI you must use the following for a 404 response:

而header("Location: xxx.com");默认是做302状态的跳转,所以它是不能给浏览器输出404错误状态的。

以上是“php如何返回错误代码”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. php如何返回数据给vue
  2. php返回数组的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php

上一篇:php头编码如何设置

下一篇:php怎样实现数字转换为大写

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》