我有太多单独的PHP文件:
我正在页面顶部的_add-new-module.php
中使用函数require_once add-new-module.php
。我已将变量$msg
初始化为_add-new-module.php
,因为某些原因它仍显示错误消息:
Notice: Undefined variable: msg in xxxxxxxxxxx/add-new-module.php on line 2
当回显$msg
中的变量_add-new-module.php
时,它会工作,但当我尝试回显$msg
中的变量add-new-module.php
时,它会给我上面的错误。当我在变量islet
上使用$msg
时,它会隐藏错误消息,但不会在页面上显示任何内容。
我还用include_once
,require_once
和require
替换了包含。仍然没有运气。我还使用全局$msg
隐藏了错误消息,但似乎没有显示结果。
答案 0 :(得分:0)
$msg
可能超出范围,请尝试添加
global $msg;
到使用它的页面。
答案 1 :(得分:0)
你可以使用全球$ msg;在add-new-module.php中,只需在echo $ msg之前写入;
global $msg;
echo $msg;
如果不工作在PHP APACHE Server Php.ini中启用全局变量Register_globals
register_globals = On
如果您想在页面中打开它,可以将代码放在代码的开头:
ini_set('register_globals',true);
否则通过.htaccess启用register_globals:
将以下代码放入其中:
//覆盖PHP设置。第一个IfModule是 //用于Apache 1.3,第二个用于Apache 2.
<IfModule mod_php4.c>
php_value register_globals 1
</IfModule>
<IfModule sapi_apache2.c>
php_value register_globals 1
</IfModule>
php_flag register_globals 1