好的,所以我正在制作一个新的登录/注册的东西,我得到错误prety快速任何人可以帮助我,我有什么不对吗?我正在观看一个教程并且正在做这个因为我是新的PHP并且对于正在制作它的人来说它很好..
我得到的错误:注意:未定义的索引:第5行的C:\ xampp \ htdocs \ loginsistem \ classes \ Config.php中的配置
我的init.php
<?php
session_start();
$GLOBALS ['confg'] = array(
'mysql' => array(
'host' => '127.0.0.1',
'username' => 'root',
'password' => '',
'db' => 'lr'
),
'remember' => array(
'cookie_name' => 'hash',
'cookie_expiry' => 604800
),
'session' => array(
'session_name' => 'user'
)
);
spl_autoload_register(function($class) {
require_once 'classes/' . $class . '.php';
});
require_once 'functions/sanitize.php';
?>
这是我的sanitize.php
<?php
function escape($string) {
return htmlentities($string, ENT_QUOTES, 'UTF-8');
}
?>
我的index.php
<?php
require_once 'core/init.php';
echo Config::get('mysql/host'); //127.0.0.1
?>
和config.php
<?php
class Config {
public static function get($path = null) {
if($path) {
$config = $GLOBALS['config'];
$path = explode('/', $path);
foreach ($path as $bit) {
if(isset($config[$bit])) {
$config = $config[$bit];
}
}
return $config;
}
}
}
?>
答案 0 :(得分:2)
你犯了一个小错误,看看你的init.php:
$GLOBALS ['confg'] = array(
它应该是'config'而不是'confg'; - )
答案 1 :(得分:0)
init.php中的配置错误
$GLOBALS ['config'] = array(
config.php第5行表明问题与数组有关。