从PHP文件显示404错误页面,无需重定向

 爱笑的美美6_833 发布于 2023-02-13 17:31

我有一个文件secret.php包含在内index.php,我想在有人试图secret.php直接访问时显示404错误页面.但

header("Location: this_site_certainly_does_not_exist");

in secure.php不是解决方案,因为我希望在example.com/secret.php显示错误页面时,用户键入的URL(例如)在浏览器的URL栏中可见,而不是重定向.

1 个回答
  • 你可以用标题来做.

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

    然后,您可以使用示例readfile方法添加404页面.

    header("HTTP/1.0 404 Not Found");
    echo "<h1>404 Not Found</h1>";
    echo "The page that you have requested could not be found.";
    exit();
    

    2023-02-13 17:34 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有