我正在尝试将密码敏感信息存储在单独的 .php 文件中。我可以将该文件包含在另一个 php 文件中(我们将其称为 php2.php)
问题是,我试图在 php1.php 上使用的代码不想回显在 php2.php 页面中指定的变量。在数组之外的任何地方,我都可以回显一个变量,它会毫无问题地显示它。我确定这只是我开始学习 PHP 时的语法错误。
任何帮助表示赞赏!谢谢你的关注。
编辑:更新!
这是我正在尝试使用的整页代码,现在在第 64 行出现错误。
<?php
require_once 'login.php';
// dota2 api key (you can get_info it here - http://steamcommunity.com/dev/apikey)
$APIkey;
//The language to retrieve results in (see http://en.wikipedia.org/wiki/ISO_639-1 for the language codes (first two characters) and http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes for the country codes (last two characters))
define ('LANGUAGE', 'en_us');
error_reporting(0);
set_time_limit(0);
/**
* Basic class with system's configuration data
*/
class LoginInfo {
/**
* Configuration data
* @access private
* @static
* @var array
*/
private static $_data = array(
'APIkey' => '',
'db_user' => '',
'db_pass' => '',
'db_host' => '',
'db_name' => '',
'db_table_prefix' => ''
);
public static function SetVar ($APIkey, $dbuser, $dbpass, $dbhost, $dbname, $Prefix = null){
self:: $_data['APIkey'] = $APIkey;
self:: $_data['db_user'] = $dbuser;
self:: $_data['db_pass'] = $dbpass;
self:: $_data['db_host'] = $dbhost;
self:: $_data['db_name'] = $dbname;
if ($Prefix === null){
self::$_data['db_table_prefix'] = '';
}else{
self::$_data['db_table_prefix'] = $Prefix;
}
}
public static function GetInfo(){
return self::$_data;
}
/**
* Private construct to avoid object initializing
* @access private
*/
private function __construct() {}
public static function init() {
self::$_data['base_path'] = dirname(__FILE__).DIRECTORY_SEPARATOR.'includes';
$db = db::obtain(echo LoginInfo::GetInfo()['db_user'], echo LoginInfo::GetInfo()['db_pass'], echo LoginInfo::GetInfo()['db_host'], echo LoginInfo::GetInfo()['db_name'], echo LoginInfo::GetInfo()['db_user']);
if (!$db->connect_pdo()) {
die();
};
}
/**
* Get configuration parameter by key
* @param string $key data-array key
* @return null
*/
public static function get($key) {
if(isset(self::$_data[$key])) {
return self::$_data[$key];
}
return null;
}
}
config::init();
function __autoload($class) {
scan(config::get('base_path'), $class);
}
function scan($path = '.', $class) {
$ignore = array('.', '..');
$dh = opendir($path);
while(false !== ($file = readdir($dh))){
if(!in_array($file, $ignore)) {
if(is_dir($path.DIRECTORY_SEPARATOR.$file)) {
scan($path.DIRECTORY_SEPARATOR.$file, $class);
}
else {
if ($file === 'class.'.$class.'.php') {
require_once($path.DIRECTORY_SEPARATOR.$file);
return;
}
}
}
}
closedir($dh);
}
?>