我有这段代码来用Zend Framework创建一个config.ini
文件,但我总是从网页中获得Internal Server Error (Error 500)
。。。
<?php
session_start();
$config = new Zend_Config_Ini('config.ini',null,array('skipExtends' => true, 'allowModifications' => true));
// CREATE VALUE
$config->database = array();
$config->base = array();
$config->system = array();
$config->home = array();
$config->other = array();
//DATABASE
$config->database->hostname = $_SESSION['db_hostname'];
$config->database->username = $_SESSION['db_username'];
$config->database->password = $_SESSION['db_password'];
$config->database->port = $_SESSION['db_port'];
$config->database->database = $_SESSION['db_name'];
// BASE
$config->base->base_url = $_SESSION['base_url'];
$config->base->site_name = $_SESSION['site_name'];
$config->base->site_slogan = $_SESSION['site_slogan'];
// SYSTEM
$config->system->license = 'false';
$config->system->cms_type = 'free';
$config->system->system_email = $_SESSION['system_email'];
// HOME
$config->home->homepage_type = 'welcome';
$config->home->blog_limit = 10;
$config->home->homepage_message = 'Welcome to CustomCMS!';
// OTHER
$config->other->copyright_text = 'Copyright &169; 2012 FMarcoux - All rights reserved';
// Write the config file
$writer = new Zend_Config_Writer_Ini(array('config' => $config,'filename' => 'config.ini'));
$writer->write();
// NOW EXECUTE SQL FILE
$sqlErrorText = '';
$sqlErrorCode = 0;
$sqlStmt = '';
$sqlFileToExecute = 'install_query.sql';
$con = mysql_connect($_SESSION['db_hostname'].':'.$_SESSION['db_port'],$_SESSION['db_username'],$_SESSION['db_password']) or die(mysql_error());
mysql_select_db($_SESSION['db_name'], $con) or die();
if ($con)
{
// Load and explode the sql file
$f = fopen($sqlFileToExecute,"r+");
$sqlFile = fread($f,filesize($sqlFileToExecute));
$sqlArray = explode(';',$sqlFile);
//Process the sql file by statements
foreach ($sqlArray as $stmt)
{
if (strlen($stmt) > 3)
{
$result = mysql_query($stmt);
if (!$result)
{
$sqlErrorCode = mysql_errno();
$sqlErrorText = mysql_error();
$sqlStmt = $stmt;
break;
}
}
}
mysql_query("INSERT INTO `users` (`id`, `username`, `password`, `role`, `full_name`, `email`, `avatar`, `avatar_type`, `ip`, `comments`, `bio`, `privacy_level`, `location`, `banned`, `user_slogan`) VALUES (1, 'admin', '".md5($_SESSION['admin_password']."', 3, 'admin', '".$_SESSION['admin_email']."', '', 'none', '127.0.0.1', 0, '', 3, '', 0, '');") or die(mysql_error());
}
if ($sqlErrorCode == 0)
{
echo "<tr><td>Installation was finished succesfully!</td></tr>";
header('Location: done.php');
}
else
{
include('header.php');
?>
<div id="main">
<h1>Writing File...</h1>
<hr />
<?php
echo "<tr><td>An error occured during installation!</td></tr>";
echo "<tr><td>Error code: ".$sqlErrorCode."</td></tr>";
echo "<tr><td>Error text: ".$sqlErrorText."</td></tr>";
echo "<tr><td>Statement:<br/> ".$sqlStmt."</td></tr>";
?>
</div>
<div id="sidebar">
<ol>
<li><strike>Welcome</strike></li>
<li><strike>Database</strike></li>
<li><strike>Admin</strike></li>
<li><strike>Basic Configuration</strike></li>
<li><b>Create 'config.ini'</b></li>
<li>Done</li>
</ol>
</div>
<div id="footer"></div>
抱歉代码太长
如果有人能帮我解决这个问题,我将不胜感激!
注意:我的所有$_SESSION[]
都已设置
我看到的两个问题是:
- 在MySQL插入中,
md5($_SESSION['admin_password']."'
需要是md5($_SESSION['admin_password'])."'
。您缺少md5的)
- 文件末尾有一个未关闭的if语句。在页脚分区后添加
<?php } ?>
您可以将应用程序设置为生产,或者打开错误报告以获取堆栈跟踪,或者在这种情况下,查看PHP语法错误消息,而不是500服务器错误。此外,error_log
文件中也应该包含错误。