我有一個網站,它連接到MySQL數據庫和它使用位於/home/user/public_html/inc/instance-config.php一個文件中定義的一些其他的密碼。PHP僅僅有時會導致錯誤500 ...。這是什麼錯誤?
我想保持對安全的/ public_html目錄上面我的密碼。基本上,我做了一個叫/home/user/secrets.php文件和主配置文件應當要求該文件,並從它那裏得到的密碼。 但它沒有。
這段代碼在我的文件/home/user/public_html/inc/instance-config.php沒有給出錯誤:
$secrets = str_replace ('public_html', '', getcwd()) . 'secrets.php';
if (file_exists($secrets)){
include $secrets ;
}
**// confirm that the values where imported**
moo('The secret value is ' . $secret_value);
$config['db']['type'] = 'mysql';
$config['db']['server'] = 'localhost';
$config['db']['database'] = 'xxxxxxx';
$config['db']['user'] = 'xxxxxxx';
$config['db']['password'] = 'xxxxxxx';
$config['cookies']['mod'] = 'xxxxxxxx';
$config['cookies']['salt'] = 'xxxxxx';
我的文件secrets.php具有相同的最後七個線,配置和密碼,以及一個名爲「secret_value」的變量,我基本上用它來檢查文件是否已被正確包含。所以,我這樣做,因爲我的「哞」功能輸出到一個日誌文件,我得到的是這樣的:
03/28/2013 07:36:52 am -- The secret value is Everything OK!
03/28/2013 07:36:55 am -- The secret value is Everything OK!
03/28/2013 07:36:55 am -- The secret value is Everything OK!
03/28/2013 06:36:56 am -- The secret value is Everything OK!
03/28/2013 07:36:57 am -- The secret value is Everything OK!
03/28/2013 06:36:57 am -- Rebuilt page 1 from ALL
03/28/2013 07:36:57 am -- The secret value is Everything OK!
03/28/2013 06:36:58 am -- The secret value is Everything OK!
03/28/2013 06:36:58 am -- The secret value is Everything OK!
03/28/2013 06:36:58 am -- The secret value is Everything OK!
03/28/2013 06:36:58 am -- The secret value is Everything OK!
03/28/2013 06:36:58 am -- The secret value is Everything OK!
03/28/2013 06:36:58 am -- The secret value is Everything OK!
03/28/2013 06:36:58 am -- The secret value is Everything OK!
03/28/2013 06:36:58 am -- The secret value is Everything OK!
03/28/2013 06:36:58 am -- The secret value is Everything OK!
03/28/2013 06:36:59 am -- The secret value is Everything OK!
03/28/2013 06:36:59 am -- The secret value is Everything OK!
03/28/2013 06:36:59 am -- The secret value is Everything OK!
03/28/2013 06:36:59 am -- The secret value is Everything OK!
03/28/2013 06:36:59 am -- The secret value is Everything OK!
03/28/2013 06:36:59 am -- The secret value is Everything OK!
03/28/2013 06:36:59 am -- The secret value is Everything OK!
03/28/2013 06:36:59 am -- The secret value is Everything OK!
03/28/2013 06:36:59 am -- The secret value is Everything OK!
03/28/2013 07:36:59 am -- The secret value is Everything OK!
因此,它似乎正在被需要的文件正確。我試圖從我的實例配置文件中刪除這些行,以便它們只出現在secret.php文件中。但首先,我試圖分支代碼,檢查文件的存在。如果文件存在,那麼它應該從中獲取配置變量。這是我的代碼:
moo(':: GET READY');
if (file_exists($secrets)){
require $secrets ;
if (isset ($secret_value))
moo('The secret value is ' . $secret_value);
else
moo('Required but could not find the secret value');
}else{
$config['db']['type'] = 'mysql';
$config['db']['server'] = 'localhost';
$config['db']['database'] = 'xxxxxx';
$config['db']['user'] = 'xxxxxxxx';
$config['db']['password'] = 'xxxxxxxxxx';
$config['cookies']['mod'] = 'xxxxxxxxxxxxx';
$config['cookies']['salt'] = 'xxxxxxxxx';
moo('The secret value was not obtained');
}
噢,是的,我得到的輸出線列表一樣:「一切OK」
03/28/2013 07:41:07 am -- :: GET READY ::
03/28/2013 07:41:07 am -- The secret value is Everything OK!
而且每個「準備好」之後的記者。在日誌文件中沒有任何地方我看到「祕密值未獲得」或「必需但找不到...」行。
然而:
在瀏覽器中,我得到一個錯誤信息和頁面加載停止。爲什麼,哦,爲什麼?我檢查過互聯網,大多數人說這可能是PHP沒有找到你的文件的問題。我試圖幫助的代碼找到該文件,就像我可以:
// this adds /home/user to the include path, because secret.php
// is located at /home/user/secret.php
if (false == strpos(ini_get('include_path'), exec('echo ~'))) {
ini_set('include_path', ini_get('include_path') . ':' . exec('echo ~'));
}
// log errors to see if we can find the cause of the problem
ini_set('log_errors', 1);
ini_set('error_log', '/home/user/errors.log');
ini_set('error_reporting', E_ALL);
// get absolute path of the file
$secrets = str_replace ('public_html', '', getcwd()) . 'secreto.php';
並沒有什麼作品,總是相同的500錯誤。我能做什麼?我嘗試了幾乎所有的東西。該文件似乎位置正確,正如我在所有執行過程中得到的輸出所示。然而,服務器給了我一個錯誤500頁面。
任何想法?
你還檢查了服務器(Apache?)錯誤日誌文件嗎? – Havelock
注意'file_exists()'不是真的可靠,因爲它會返回true,如果你傳遞一個目錄名。更好地使用'is_file()'。 – Havelock
但不是代碼找到屬於該文件一部分的「secret_value」的值,足以證明該文件被正確包含?爲什麼500? –