遇到问题 - $_SERVER['SERVER_NAME']

发布于 2025-01-08 04:55:34 字数 907 浏览 2 评论 0原文

我知道我正在做一些愚蠢且可能显而易见的事情,但我不确定是什么。在我的 header.php 中,我有:

define('ABSPATH', $_SERVER['SERVER_NAME']);
require_once(ABSPATH . "/config.php");

使用它会产生以下错误:

Warning: require_once(localhost/config.php): failed to open stream: 
No such file or directory in C:\wamp\www\inc\header.php on line 4 
Call Stack: 0.0002 684176 1. {main}() C:\wamp\www\index.php:0 0.0003 
696152 2. require_once('C:\wamp\www\inc\header.php') C:\wamp\www\index.php:2 
Fatal error: require_once(): Failed opening required 'localhost/config.php' (include_path='.;C:\php\pear') in C:\wamp\www\inc\header.php on line 4 Call Stack: 
0.0002 684176 1. {main}() C:\wamp\www\index.php:0 0.0003 696152 2. require_once('C:\wamp\www\inc\header.php') C:\wamp\www\index.php:2

但是,如果我直接导​​航到 localhost/config.php (目前,它只是一个简单的 1 行回显句子的文件)它会起作用。

我做错了什么?

I know I'm doing something stupid and probably obvious, but I'm not sure what. In my header.php I have:

define('ABSPATH', $_SERVER['SERVER_NAME']);
require_once(ABSPATH . "/config.php");

Using this produces the following error:

Warning: require_once(localhost/config.php): failed to open stream: 
No such file or directory in C:\wamp\www\inc\header.php on line 4 
Call Stack: 0.0002 684176 1. {main}() C:\wamp\www\index.php:0 0.0003 
696152 2. require_once('C:\wamp\www\inc\header.php') C:\wamp\www\index.php:2 
Fatal error: require_once(): Failed opening required 'localhost/config.php' (include_path='.;C:\php\pear') in C:\wamp\www\inc\header.php on line 4 Call Stack: 
0.0002 684176 1. {main}() C:\wamp\www\index.php:0 0.0003 696152 2. require_once('C:\wamp\www\inc\header.php') C:\wamp\www\index.php:2

However, if I navigate directly to localhost/config.php (currently, it's just a simple 1 line file that is echoing a sentence) It will work.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一张白纸 2025-01-15 04:55:34

$_SERVER['DOCUMENT_ROOT'] 应该可以解决问题

$_SERVER['DOCUMENT_ROOT'] should do the trick

我早已燃尽 2025-01-15 04:55:34

include 以及从服务器看到的与文件一起使用的任何其他内容都与文件系统路径一起使用。 C:\foo\bar 是文件系统路径。 localhost 不是,localhost 是从网络中看到的 URL 的主机名。文件 localhost/config.php 在被视为网络上的 URL 时有效。本地系统上的同一文件具有类似 C:\wamp\www\config.php 的路径,这是您需要使用 require_once 它的路径。

includes and anything else that works with files as seen from the server work with file system paths. C:\foo\bar is a file system path. localhost is not, localhost is the hostname of a URL as seen from the network. The file localhost/config.php is valid when treated as a URL over a network. The same file on the local system has a path like C:\wamp\www\config.php, which is what you need to use to require_once it.

樱桃奶球 2025-01-15 04:55:34

您确定您不是想在 Windows 系统上使用反斜杠吗?

另外,请确保该文件位于 Web 根目录中的 localhost 文件夹

Are you sure you didn't mean to use a backslash on your Windows system, there?

Also, make sure the file is in the localhost folder within your web root.

偏爱自由 2025-01-15 04:55:34

尝试以下:

define('ABSPATH', $_SERVER['DOCUMENT_ROOT']);
require_once(ABSPATH . "/config.php");

Try below :

define('ABSPATH', $_SERVER['DOCUMENT_ROOT']);
require_once(ABSPATH . "/config.php");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文