我知道我在做一些愚蠢的事,可能很明顯,但我不知道是什麼。在我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行文件)它會工作。
我在做什麼錯?
+1你是正確的,爲什麼'本地主機/ config.php'在他的瀏覽器的工作原理的解釋,但不要求將是很好的,但。描述'URL的fopen wrappers'以及如何與他們打開'要求(「HTTP://」 ABSPATH「/config.php」。)'會的工作,爲什麼這是一個壞主意,都將是不錯的。 – Paulpro 2012-02-22 00:25:56
這樣做的竅門,謝謝! @ PaulP.R.O。 - 你能解釋爲什麼這是一個壞主意嗎?我應該使用什麼? – 2012-02-22 00:30:57
在'http'中使用'require'是個壞主意,因爲你所有的require/includes都將通過http來完成。這是沒有必要的,因爲你的文件在同一臺服務器上,你可以打開它。 '$ _SERVER ['DOCUMENT_ROOT']'會給你的webroot文件系統路徑。從那裏你可以訪問config.php。 – Paulpro 2012-02-22 00:35:20