以前从未遇到过这种情况,但是在if()语句中测试用户编写的函数是否存在问题?
我在位于不同服务器(称为"myPhpInclude.php")的单独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...';
}
?>
摘自我的 HTML 文档,该文档与 PHP 包含文件位于单独的服务器上:
<?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>
网页在我的 if() 语句点停止渲染并且不返回任何错误。PHP 错误调试已激活并打开。
谢谢。
等等等等,你有$phrase和$phase吗?我认为这是一个错字。
那里:
function displayIt($phrase = NULL) { <== phrase
if (is_null($phase)) <== phase
如果没有,请尝试将其放在try{}块中,尝试echo displayIt('on');
,也许由于某种原因它返回false。
编辑:而不是include('http://mydomain.com/includes/myPhpInclude.php');
尝试include('./includes/myPhpInclude.php');
或将其替换为包含文件的文件系统路径。
即使cross_domain_include有效,从 url 获取 php 文件也不会给你 php 代码,而是输出(在这种情况下为空)。
问题出在包含文件上:
include('http://mydomain.com/includes/myPhpInclude.php');
将通过普通 HTTP 请求从服务器http://mydomain.com
请求文件includes/myPhpInclude.php
。您将收到的不是php代码,而是Web服务器运行该php文件时的输出。即使在某些条件下:
PHP4.3.0 之前的 Windows 版本的 PHP 不支持通过此功能访问远程文件,即使启用了allow_url_fopen也是如此。
您需要做的是通过本地文件系统包含文件,使用相对路径(或文件系统的绝对路径),例如:
include 'includes/myPhpInclude.php';
您在
第二个变量中拼写错误的"短语"。