处理我自己的函数的if()语句的意外结果

Never ran into this before, but is there a problem testing a user-written function within an if() statement?

I have the following in a separate PHP includes file located on a different server (called "myPhpInclude.php"):

<?php

error_reporting(E_ALL);
ini_set('display_errors','On');

function displayIt($phrase = NULL) {
    if (is_null($phrase)) return false;
    else return true;
}

if ($_SERVER['REMOTE_ADDR'] == '123.456.789.012') { /* my ip address */
    echo 'include file is coming in ok...';
}

?>

Excerpt from my HTML document on a separate server from the PHP includes file:

<?php include('http://mydomain.com/includes/myPhpInclude.php'); /* the displayIt() function is contained in this include file */ ?>

...

<div id="content">
<?php if (displayIt('on')) { /* <-- MY PROBLEM ORIGINATES HERE */?>
    <p>Some content.</p>
<? } ?>
</div>

The web page stops rendering at the point of my if() statement and returns no errors. PHP error debugging is activated and on.

Thanks.

The problem is with the include file:

include('http://mydomain.com/includes/myPhpInclude.php');

will request the file includes/myPhpInclude.php from the server http://mydomain.com via a normal http request. What you will receive is not php code but the output from the web-server when it runs that php file. And that even under certain conditions:

Windows versions of PHP prior to PHP 4.3.0 do not support access of remote files via this function, even if allow_url_fopen is enabled.

What you need to do, is include the file via the local filesystem, using a relative path (or an absolute path to the file system), like for example:

include 'includes/myPhpInclude.php';

You spelled "phrase" wrong in the second variable.

Wait wait wait, do you have $phrase and $phase? I think it's a typo.

There:

function displayIt($phrase = NULL) { <== phrase
    if (is_null($phase))             <== phase

If not, try putting it in a try{} block, try echo displayIt('on');, maybe it returns false for some reason.

Edit: instead of include('http://mydomain.com/includes/myPhpInclude.php'); try include('./includes/myPhpInclude.php'); or replace it with the filesystem path of the included file.

Even if cross_domain_include was effective, fetching the php file from the url wouldn't give you the php code, but rather the output (which would be empty in this case).