×

header 404

header 404(thinkphp 怎么设置404)

admin admin 发表于2022-09-05 01:11:10 浏览220 评论0

抢沙发发表评论

本文目录

thinkphp 怎么设置404


首先应该尝试在服务器添加,其实没这个必要,thinkphp自身便提供了404页面的处理机制,我们只需要在lib下定义一个EmptyAction.class.php,且实现以下方法即可,如下:
《?php
class EmptyAction extends Action {
function _empty(){
header(“HTTP/1.0 404 Not Found“);
$this-》display(’Public:404’);
}
// 404
function index() {
header(“HTTP/1.0 404 Not Found“);
$this-》display(’Public:404’);
}
}
?》
以上通过直接定义空模块和空操作实现404跳转,但要注意的是:
设置header头很重要, 不然的话返回的状态会是200.
该类对应Public模板目录下需要有名为404的页面模板.

php中如何让页面返回404错误代码呢


php中用header()函数是可以为返回页面添加404的头信息的,从而提示浏览器该网页找不到了。所以可以使用:header(“HTTP/1.0 404 Not Found“);或者:header(“Status: 404 Not Found“);后者是在FastCGI模式下使用的,在php代码中可以把两句直接同时写上。摘抄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动态页面设置了header(“Status: 404 Not Found“);但返回200状态


if($id!=1){
header(“HTTP/1.0 404 Not Found“);
header(“Status: 404 Not Found“);
exit();
}
或者
if($id!=1){
header(“HTTP/1.1 404 Not Found“);
header(“Status: 404 Not Found“);
exit();
}
-header 404

php header 返回状态吗


面试时很多人问我这个,记录一下   200是ok,  404表示页面未找到.
HTTP协议状态码,调用函数时候只需要将$num赋予一个下表中的已知值就直接会返回状态了。
《?PHP 
/** 
* HTTP Protocol defined status codes
* HTTP协议状态码,调用函数时候只需要将$num赋予一个下表中的已知值就直接会返回状态了。
* @param int $num
*/ 
function https($num) { 
$http = array ( 
100 =》 “HTTP/1.1 100 Continue“, 
101 =》 “HTTP/1.1 101 Switching Protocols“, 
200 =》 “HTTP/1.1 200 OK“, 
201 =》 “HTTP/1.1 201 Created“, 
202 =》 “HTTP/1.1 202 Accepted“, 
203 =》 “HTTP/1.1 203 Non-Authoritative Information“, 
204 =》 “HTTP/1.1 204 No Content“, 
205 =》 “HTTP/1.1 205 Reset Content“, 
206 =》 “HTTP/1.1 206 Partial Content“, 
300 =》 “HTTP/1.1 300 Multiple Choices“, 
301 =》 “HTTP/1.1 301 Moved Permanently“, 
302 =》 “HTTP/1.1 302 Found“, 
303 =》 “HTTP/1.1 303 See Other“, 
304 =》 “HTTP/1.1 304 Not Modified“, 
305 =》 “HTTP/1.1 305 Use Proxy“, 
307 =》 “HTTP/1.1 307 Temporary Redirect“, 
400 =》 “HTTP/1.1 400 Bad Request“, 
401 =》 “HTTP/1.1 401 Unauthorized“, 
402 =》 “HTTP/1.1 402 Payment Required“, 
403 =》 “HTTP/1.1 403 Forbidden“, 
404 =》 “HTTP/1.1 404 Not Found“, 
405 =》 “HTTP/1.1 405 Method Not Allowed“, 
406 =》 “HTTP/1.1 406 Not Acceptable“, 
407 =》 “HTTP/1.1 407 Proxy Authentication Required“, 
408 =》 “HTTP/1.1 408 Request Time-out“, 
409 =》 “HTTP/1.1 409 Conflict“, 
410 =》 “HTTP/1.1 410 Gone“, 
411 =》 “HTTP/1.1 411 Length Required“, 
412 =》 “HTTP/1.1 412 Precondition Failed“, 
413 =》 “HTTP/1.1 413 Request Entity Too Large“, 
414 =》 “HTTP/1.1 414 Request-URI Too Large“, 
415 =》 “HTTP/1.1 415 Unsupported Media Type“, 
416 =》 “HTTP/1.1 416 Requested range not satisfiable“, 
417 =》 “HTTP/1.1 417 Expectation Failed“, 
500 =》 “HTTP/1.1 500 Internal Server Error“, 
501 =》 “HTTP/1.1 501 Not Implemented“, 
502 =》 “HTTP/1.1 502 Bad Gateway“, 
503 =》 “HTTP/1.1 503 Service Unavailable“, 
504 =》 “HTTP/1.1 504 Gateway Time-out“  
); 
header($http[$num]); 

?》
@header(’HTTP/1.0 404 Not Found’);
-header 404

thinkPHP到底怎么设置404错误页面


1、首先要在Lib/Action 下建立EmptyAction.class.php模块
内容如下:
复制代码 代码如下:
《?php
/*
* @author rocky
* @date 20141021
* @desc 空模块404等错误
* */
class EmptyAction extends CommonAction {
function _empty(){
header(“HTTP/1.0 404 Not Found“);
$this-》display(’Public:404’);
}
}
?》
2、做完以上处理,只能在访问到空模块的时候才会访问404页面,所以,为了访问空方法也访问404页面,我们还需要在CommonAction.class.php增加一个空方法了,方法如下:
复制代码 代码如下:
//处理所有没有的方法的处理方法,引导到404页面
public function _empty() {
R(’Empty/_empty’);
}
3、做完以上工作基本可以了,但是别忘了把你的404.html页面放在Tpl/Public下
-header 404

新手,用python写的爬虫,为什么出现404


可能是你的header写的太简单了,我刚刚也是一直404,因为一开始我的header里只有User-Agent,再加上Accept,Accept-Encoding,Content-Type,Host,Origin,Proxy-Connection,Referer,Upgrade-Insecure-Requests就行了,这些都可以从chrome的开发者工具里直接看,或者用fiddler等工具看。
-header 404

PHP动态页面如何让页面返回404状态码


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

这个我刚试了下是可以的,应该是你这句话不是在页面的顶部,而是中间,顶部默认就输出一个200了。


用php设置header返回404 但是页面空白 是不是和php.ini/nginx有关


404 not found
未找到该网页,说明此网页已经在服务器被删除或被改名。在安全助手里添加黑名单,把这个网站的网址输入进去。不让他弹出。
404是对NOT FOUND这种错误情况的一个编码,HTTP协议的错误信息在不同软件、不同的语言描述可能不同,但是其代码是统一的,以便浏览器能够正确识别和处理。
-header 404