php – $_SERVER [‘document_root’]返回/ htdocs not / public_html

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – $_SERVER [‘document_root’]返回/ htdocs not / public_html脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在寻找切换到新主机,他们提供这个漂亮的小“临时网址”来测试你的文件切换之前.一切都很好,花花公子.所以我复制了我的所有文件.在每个页面的顶部,我需要来自服务器的另一个文件,该文件存储在Public_htML / includes / head.PHP中.现在无论出于何种原因,$_SERVER [‘document_root’] VAR返回/public_html/htdocs/includes/head.PHP(服务器上不存在)而不是/public_html/includes/head.PHP(确实存在) .产生的错误如下:

@H_304_7@Warning: require_once(/home/secure31/public_html/htdocs/includes/head.PHP) [function.require-once]: Failed to oPEn stream: Permission denied in /home/stephe80/public_html/index.PHP on line 6

有罪的代码

require_once($_SERVER['DOCUMENT_ROOT'] . '/includes/head.PHP');

我倾向于认为这是与他们的临时网址设置相关的错误,但我不想通过我的DNS转移并发现我的所有文件都被破坏了.我可以将它们改为绝对路径,但我很好奇我是否遗漏了一些东西.任何见解将不胜感激.谢谢!

解决方法

我建议使用 __FILE__常量并从那里计算你的htdocs文件夹.它比依赖$_SERVER超全局更可靠,因为它实际上因服务器而异.

示例(您在根文件夹中的index.PHP调用):

$htdocs = str_replace(basename(__FILE__),__FILE__,'');
define('ROOT_FOLDER',$htdocs);
require_once(ROOT_FOLDER . '/includes/head.PHP');

脚本宝典总结

以上是脚本宝典为你收集整理的php – $_SERVER [‘document_root’]返回/ htdocs not / public_html全部内容,希望文章能够帮你解决php – $_SERVER [‘document_root’]返回/ htdocs not / public_html所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。