[英]Undefined variable error
嗨,我是Denis,我是php的新手。 我的父親是一名PHP開發人員,但我想自己做。 我今年11歲!!! :)
我為我的php東西做了一個安裝程序,但出現此錯誤:
Notice: Undefined variable: config in \path\to\core.php on line 20
這是失敗的部分:
$system['home_url'] = "".$config['home']['url']."";
但是,如果我之前包含配置文件並且此變量不是未定義的,它將如何失敗!
我做了: require('config.php');
config.php文件代碼為:
$config['home']['url'] = "http://localhost/";
我使用的變量正確嗎? 我搜索了所有的互聯網,只找到了使用global
解決方案,但我真的不知道它是如何工作的。
再見! 並感謝:)))
編輯-Core.PHP
<?PHP
/*=======================================================================
| #######################################################################
| This program is free software: you can redistribute it and/or modify
| it under the terms of the GNU General Public License as published by
| the Free Software Foundation, either version 3 of the License, or
| (at your option) any later version.
| #######################################################################
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
\======================================================================*/
require('config.php');
$system['home_url'] = "".$config['home']['url']."";
$system['updates_enabled'] = "".$config['updates']['enabled']."";
$system['update_url'] = "".$config['update']['url']."";
$system['language'] = $config['language'];
$system['favicon'] = "".$config['favicon']."";
$system['maintenance_status'] = "".$config['maintenance']['status']."";
$system['version'] = "".$config['version']."";
$system['master_user'] = "".$config['master']['user']."";
$system['master_password'] = "".$config['master']['password']."";
$system['config_path'] = "config.php";
/*====================================================================*/
$site['name'] = "".$config['site']['name']."";
$site['desc'] = "".$config['site']['desc']."";
/*====================================================================*/
$cloud_panel['reload_time'] = "".$config['reload']['time']."";
/*====================================================================*/
require "".$system['home_url']."lang/lang_".$system['language'].".php";
/*====================================================================*/
$template['id'] = "".$config['template']['id']."";
$template['webgallery_type'] = "".$config['webgallery']['type']."";
$template['webgallery_url'] = "".$config['webgallery']['url']."";
/*====================================================================*/
if(isset($_GET['help'])) { header('Location: '.$system['home_url'].'help.php'); }
/*====================================================================*/
if ($template['webgallery_type'] == 1) { $template['my_webgallery'] = "".$system['home_url']."cdn/web-gallery"; } else { $template['my_webgallery'] = $template['webgallery_url']; }
/*====================================================================*/
?>
配置文件
<?PHP
/*=======================================================================
| #######################################################################
| This program is free software: you can redistribute it and/or modify
| it under the terms of the GNU General Public License as published by
| the Free Software Foundation, either version 3 of the License, or
| (at your option) any later version.
| #######################################################################
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
\======================================================================*/
$config['site']['name'] = "heya";
$config['site']['desc'] = "heya";
$config['home']['url'] = "http://localhost/";
$config['updates']['enabled'] = "1";
$config['update']['url'] = "http://localhost/update";
$config['language'] = "es";
$config['favicon'] = "favicon.ico";
$config['maintenance']['status'] = "1";
$config['reload']['time'] = "10";
$config['version'] = "1.3.4";
$config['master']['user'] = "heya";
$config['master']['password'] = "heya";
$config['template']['id'] = "9";
$config['webgallery']['type'] = "1";
$config['webgallery']['url'] = "heya";
?>
使用lik isset($config['home']['url'])
之前檢查變量,您也可以使用!empty($config['home']['url'])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.