不能使用子域包含来自root的php文件

问题描述 投票:0回答:3

我最近为api制作了一个API我已经创建了一个子域但是它打破了我的php文件包含

include $_SERVER['DOCUMENT_ROOT'].'/core/init.php';

现在我使用的子域是api.website.com,当我尝试包含它给出子域的根时,我需要包含来自website.com的东西,

总结当我尝试包含init.php时,我得到了

Warning: include(/home/website/public_html/API/core/init.php): failed to open stream: No such file or directory in /home/website/public_html/api/apex/getusers.php on line 2

当我真的需要的时候

Warning: include(/home/website/public_html/core/init.php): failed to open stream: No such file or directory in /home/website/public_html/api/apex/getusers.php on line 2

如果需要,我为我的语法道歉。

php include-path
3个回答
1
投票

将包含路径更改为

include ("../../core/init.php");

将解决您的问题。但是,这不是推荐的方法。

你应该考虑使用像composer这样的依赖管理器。 (https://getcomposer.org/)。然后,您包含的文件将始终位于类似的目录下

/home/website/public_html/vendor/core

如果/ home / website / public_html / core中的文件发生变化,您的应用程序破坏的可能性就会降低。


0
投票

这应该工作。

    include("../core/init.php");

0
投票

使用以下代码

include_once $_SERVER['DOCUMENT_ROOT'] .  '/../core/init.php';

访问https://developer.hyvor.com/php/including-files-in-root-with-subdomain.php了解更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.