php的header函数返回404失败
刚学习php,学到header的时候试着使用
header("http/1.1 404 Not Found");
但是运行之后没有反应,网上说这句话应该放在文件开头,整个文件如下:
<?php header("http/1.1 404 Not Found"); ?> <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <?php // put your code here echo "hello"; ?> </body> </html>
<!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> hello </body> </html>
现在想知道这个需要apache或者是php额外配置什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
用浏览器开发者工具查看请求返回的状态。
两者不冲突
404 状态 后边 也可以继续写入内容
很多网站 也都是 自定义的 404页面
header之后调用exit(); 也就真没有后续的内容了。。
明白了…
header之后调用exit();
我在netbeans的网络监视器中发现了: Request URL: http://localhost/PhpProject1/index.php Method: GET Status: 404 倒是找到了404的代码,但是为什么还是显示了下面的网页呢,不是应该直接显示网页未找到么。
回复
那是IE专用。。。现在都是返回404同时显示一个引导页面
代码没问题,注意规范header('HTTP/1.1 404 Not Found');
打开Chrome的控制台查看