我有一个网站,它连接到一个mysql数据库,它使用一些其他密码,这些密码在/home/user/public_html/inc/instance-config.php中的文件中定义。
为了安全起见,我想将密码保存在/ 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 ”的变量,我基本上用它来检查文件已被正确包括在内。所以,我这样做,因为我的“ moo ”函数输出到日志文件,我得到类似的东西:
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!
因此,似乎正确地要求该文件。我试图从我的instance-config文件中删除这些行,以便它们只出现在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');
}
哦,是的,我得到一个输出行列表,如:
03/28/2013 07:41:07 am -- :: GET READY ::
03/28/2013 07:41:07 am -- The secret value is Everything OK!
每个“GET READY”之后都是通讯员“一切都好!”。在日志文件中没有任何地方我看到“未获得秘密值”或“必需但无法找到...”行。
然而:
在浏览器中,我收到错误500 消息,页面停止加载。为什么,为什么?我已经检查了互联网,大多数人都说这可能是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页。
有什么想法吗?
答案 0 :(得分:1)
你看到了什么是php错误吗?错误500是webserver / apache说php有问题。 问题本身很可能是在webserver / apache error_log文件中。
或者,从命令行运行你的php文件(php -l somefile.php
可以进行语法检查),php会告诉你问题(语法或运行时),从托管它的同一目录运行文件,如{{ 1}}。