0

いくつかrequire_once()問題があります。

コード:

<?php 
$serverName = $_SERVER['SERVER_NAME'];

if ($serverName != 'xxx.xxx.xxx.xxx') {
    require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
    } else {
    require_once($_SERVER['SERVER_NAME'] . "/config.php");
    }
?>

エラー/警告:

Warning: require_once() [function.require-once]: Unable to accesss xxx.xxx.xxx.xxx/config.php in /var/www/vhosts/site.com/httpdocs/inc/header.php on line 7


Warning: require_once(xxx.xxx.xxx.xxx/config.php) [function.require-once]: failed to open stream: No such file or directory in /var/www/vhosts/site.com/httpdocs/inc/header.php on line 7


Fatal error: require_once() [function.require]: Failed opening required 'xxx.xxx.xxx.xxx/config.php' (include_path='.:') in /var/www/vhosts/site.com/httpdocs/inc/header.php on line 7

The config.php file is being called in my header.php file. Everything works great locally, but once it's on the live server, I just get the errors above.

Not sure if it matters, but I'm accessing this via IP address since it's a development site.

Yes, the config.php files does exist in the root directory.

Any ideas?

4

2 に答える 2

0

require_once にはスクリプトの絶対パスが必要ですが、 $_SERVER['SERVER_NAME'] はパスの代わりに URL を指定するため、ロードに失敗します。

require_once($_SERVER['SERVER_NAME'] . "/config.php");
于 2012-02-28T01:11:55.563 に答える
0

相対パスを使用して構成ファイルにアクセスすることをお勧めします。

<?php 
//header.php
$serverName = $_SERVER['SERVER_NAME'];

if ($serverName == 'localhost' || $serverName == '127.0.0.1') {
    require_once("./local_config.php");
}else{
    require_once("./config.php");
}
?>
于 2012-02-28T01:27:02.233 に答える