我有一个文件secret.php
包含在内index.php
,我想在有人试图secret.php
直接访问时显示404错误页面.但
header("Location: this_site_certainly_does_not_exist");
in secure.php
不是解决方案,因为我希望在example.com/secret.php
显示错误页面时,用户键入的URL(例如)在浏览器的URL栏中可见,而不是重定向.
你可以用标题来做.
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();