为什么我得到1而不是所需的文件?

eli*_*byy 0 php require

可能重复:
包括来自另一台服务器的php文件

我想拥有自己的错误系统而不是php错误,所以例如我需要来自另一台服务器的文件,而且该服务器现在不可用

<?php
require 'http://example.com/file.php' or die ("that host is not available right now");
?>
Run Code Online (Sandbox Code Playgroud)

但我得到了

警告:require(1)[function.require]:无法打开流:第5行的C:\ xampp\htdocs\index.php中没有这样的文件或目录

致命错误:require()[function.require]:在第5行的C:\ xampp\htdocs\index.php中打开所需的'1'(include_path ='.; C:\ xampp\php\PEAR')失败

dec*_*eze 6

这是因为require 'foo' or bar()被解释为require ('foo' or bar()).'foo' or bar()等于true,即1.如果你想这样写,请使用不同的括号:

(require 'http://example.com/file.php') or die ("that host is not available right now");
Run Code Online (Sandbox Code Playgroud)

但是,这里根本不需要die,因为require如果无法加载所需的文件,它将暂停程序执行.只是require 'http://example.com/file.php';会做得很好.是否应该通过网络实际加载外部PHP文件是另一个故事(提示:可能不是).