Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP自动预结束和http 404错误_Php - Fatal编程技术网

PHP自动预结束和http 404错误

PHP自动预结束和http 404错误,php,Php,我已经安装了Apache和PHP,并且我正在使用.htaccess文件来自动为任何输出预先添加文件 问题是当我想使用 <?php header("HTTP/1.0 404 Not Found"); ?> load.php <?php // Set the error reporting level (DEV) error_reporting(E_ALL); ini_set("display_errors", 1); // Load the

我已经安装了Apache和PHP,并且我正在使用
.htaccess
文件来自动为任何输出预先添加文件

问题是当我想使用

<?php header("HTTP/1.0 404 Not Found"); ?>
load.php

<?php

    // Set the error reporting level (DEV)
    error_reporting(E_ALL);
    ini_set("display_errors", 1);

    // Load the configuration file
    include("config/config.php");

    session_start();

?>

因此,加载文件包含配置文件的include,以便在加载的每个页面上设置它

因此,目前我有一些页面给出了软404错误,而不是实际的404错误,所以如果没有返回数据,比如浏览到/image/123,因为image 123实际上不存在,我会输出一个“This image not exist”,这会给谷歌或任何其他爬虫程序带来问题,因为它可以继续从/image/123/图/1222222333333444444等。。。所以它实际上需要输出一个合适的404


希望有人能帮忙。

我在以下方面找到了答案:



这将提供正确的404输出。

首先告诉我们自动预设文件中的内容。@Jack,已经在上面添加了该文件。在
load.PHP
中的PHP标记周围是否有空格?@Oscar,没有,没有空格。
<?php

    // Set the error reporting level (DEV)
    error_reporting(E_ALL);
    ini_set("display_errors", 1);

    // Load the configuration file
    include("config/config.php");

    session_start();

?>
<?php
header("HTTP/1.0 404 Not Found");
exit("<h1>Not Found</h1>
The requested URL " . $_SERVER["REQUEST_URI"] . " was not found on this server.
<hr>");
?>