php包含其他php文件

1 php include server-side-includes nested-includes

我现在变得非常混乱,我的大脑疼!:( 大声笑

根:

  • 的index.php

包括:

  • cat.php
  • dog.php

index包括dog:include("includes/dog.php");

狗包括猫:include("cat.php");

当我运行索引时,对于cat,它说:

  1. 无法建立到服务器的链接
  2. 访问被拒绝用户...

但是,如果我跑狗,我没有问题......

我猜它的路径,但我试过./includes/cat.php没有快乐......

Bar*_*lom 5

这是因为当您包含相对路径时,它相对于入口点(第一个PHP文件,由Web服务器调用).

在狗,做

include(dirname(__FILE__) . '/cat.php'); // __FILE__ is always the name of the php file it's in
Run Code Online (Sandbox Code Playgroud)