【发布时间】:2017-08-01 23:25:11
【问题描述】:
我的index.php 包括header.php 和footer.php 这样一来:
define("LEGAL_PATH", TRUE);
include("header.php");
// ...
include("footer.php");
我包含的每个文件都以:
if (!defined("LEGAL_PATH"))
{
header("location: index.php");
exit(0);
}
目前,当我们加载header.php(或footer.php)时,我们会被重定向到index.php 页面。当我们尝试 curl header.php 时,它会返回一个空白页(感谢 exit(0))。
问题:
关于坏人,我想生成一个 404 错误(例如,当我们尝试访问 efjiozfjoijefiojzeof.php 时)即使我们使用 curl 加载页面:在这种情况下(使用 curl 命令),标题位置是非功能性的。
我的 curl 输出(没有exit(0)时):
$> curl https://www.mywebsite.com/header.php
NOBODY SHOULD READ THIS DIRECTLY FROM HEADER.PHP FILE
我目前拥有的 curl 输出(当有 exit(0) 时):
$> curl https://www.mywebsite.com/header.php
$>
我想要的 curl 输出:
$> curl https://www.mywebsite.com/header.php
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /headzefjzefjp.php was not found on this server.</p>
</body></html>
$>
我的想法是包含 404 页面文件,但是当我在详细模式下 curl 时,我仍然有 200 错误代码(而不是 404):
$> curl https://.../header.php -v
...
> GET /header.php HTTP/1.1
> Host: ...
> User-Agent: curl/7.51.0
> Accept: */*
>
< HTTP/1.1 200 OK
...
那么,真正忽略 header.php 文件(来自浏览器、curl 等)的好方法是什么?
【问题讨论】:
-
header("HTTP/1.0 404 Not Found");- 必须在显示任何内容之前调用。