dongtan7639 2013-02-27 11:32
浏览 35
已采纳

包含文件中的PHP定义值丢失

I have a config.php file with this line in it:

define("home_dir",'soft06/site_name');

In index.php file I have:

include_once ("config.php")
... some html code ....
include_once (home_dir."/footer.php")

That works well. However if in footer.php I put this line:

echo("home_dir=".home_dir);

I get:

Notice:  Use of undefined constant home_dir - assumed 'home_dir' in <b>D:\xampp\htdocs\footer.php on line 3
home_dir=home_dir

But if I choose to include footer.php like this: include_once ("footer.php") instead of include_once (home_dir."/footer.php") It works fine.

It seems to me that if I use the constant home_dir in include_once function I will lose the home_dir value within the include file.

Any help would be appreciated.

  • 写回答

1条回答 默认 最新

  • duanqi5114 2013-02-28 06:06
    关注

    So you

    include_once (home_dir."/footer.php")
    

    trying to include file over http :^ ) And it have been executed before inclusion. So footer.php running in another http request and there for home_dir was not defined.

    You must use local path for including.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入