Possible Duplicate:
including php file from another server with php
i want to have my own error system instead of having the php errors so for example i require a file from another server and that server is not available right now
<?php
require 'http://example.com/file.php' or die ("that host is not available right now");
?>
but instead i get
Warning: require(1) [function.require]: failed to open stream: No such file or directory in C:\xampp\htdocs\index.php on line 5
Fatal error: require() [function.require]: Failed opening required '1' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\index.php on line 5
It's because require 'foo' or bar()
is interpreted as require ('foo' or bar())
. 'foo' or bar()
equals true
, i.e. 1
. If you want to write it like this, use different parentheses:
(require 'http://example.com/file.php') or die ("that host is not available right now");
But, you don't need die
at all here, since require
will already halt program execution if the required file can't be loaded. Just require 'http://example.com/file.php';
will do fine. Whether you should actually load foreign PHP files over the network is another story (hint: probably not).
The problem is the precedence of operators. The PHP are including the result of the "or" comparison (true). Try to remove this.
include('http://...') or die('error...');
It will work.
精彩评论