📄 install.php
字号:
<?php
error_reporting(E_ALL & ~E_NOTICE);
if(eregi('WIN',PHP_OS)) date_default_timezone_set('Asia/Shanghai');
$rootpath = '../';
// ############################## INCLUDE VERSION ##############################
include($rootpath . 'install/version.php');
$default_server = "http://". $_SERVER['HTTP_HOST'] . str_replace("/install/install.php","",$_SERVER['SCRIPT_NAME']) . "/";
// ############################## HEADER AND FOOTER ############################
echo '<html>
<head>
<title>多多留言本安装程序</title>
<link rel="stylesheet" href="./styles.css" />
</head>
<body>
<table width="480" cellpadding="0" cellspacing="1" border="0" align="center" class="box">
<tr>
<td class="title">多多留言本 '.$book_version.' 安装程序</td>
</tr>
<tr>
<td valign="top" style="padding: 5px;"><br />';
// store the footer in a var since it will be used in different parts of this file
$footer = ' </td>
</tr>
</table>
</body>
</html>';
// ################# CHECK IF WEENCOMPANY IS ALREADY INSTALLED ##################
@include($rootpath . 'include/config.php');
if(defined('MCBOOKINSTALLED'))
{
echo '<font class=ohred><b>多多留言本已经安装!</b></font><br />
如果您希望删除原数据并重新安装,请先清除include目录下的config.php文件内容。';
echo $footer;
exit();
}
// #################### CHECK CONFIG EXISTS AND IS WRITABLE ####################
if(!file_exists($rootpath . 'include/config.php'))
{
echo '<font class=ohred><b>配置文件config.php不存在!</b></font><br/>
请用记事本编辑一个空文件并上传到include目录。<br /><br />
Unix或Linux服务器系统下,需要先将config.php文件属性设置为766。<br />
为了安全起见,安装完成后需将config.php文件属性设置为644。';
echo $footer;
exit();
}
else if(!is_writable($rootpath . 'include/config.php'))
{
@chmod($rootpath . "include/config.php", 0776);
if(!is_writable($rootpath . 'include/config.php'))
{
echo '<font class=ohred><b>config.php文件不可写!</b></font><br />
config.php文件不可写! Unix或Linux服务器系统下,需要先将config.php文件属性设置为766。<br /><br />
为了安全起见,安装完成后需将config.php文件属性设置为644。';
}
echo $footer;
exit();
}
else
{
// Also try and actually open the file in case we are running on Windows
// as they user may not have access to the file
if(!$fp = @fopen($rootpath . 'include/config.php', "w"))
{
echo '<font class=ohred><b>config.php文件不可写!</b></font><br />
config.php文件不可写! 需要先将config.php文件属性设置为可写。<br /><br />
为了安全起见,安装完成后需将config.php文件属性设置为不可写。';
echo $footer;
exit();
}
}
// ############################### GET POST VARS ###############################
$servername = isset($_POST['install']) ? $_POST['servername'] : 'localhost';
$dbname = isset($_POST['install']) ? $_POST['dbname'] : '';
$dbusername = isset($_POST['install']) ? $_POST['dbusername'] : '';
$dbpassword = isset($_POST['install']) ? $_POST['dbpassword'] : '';
$tableprefix = isset($_POST['install']) ? $_POST['tableprefix'] : 'gb_';
$username = isset($_POST['install']) ? $_POST['username'] : '';
$password = isset($_POST['install']) ? $_POST['password'] : '';
$confirmpassword = isset($_POST['install']) ? $_POST['confirmpassword'] : '';
// ############################ INSTALL WEENCOMPANY #############################
if(isset($_POST['install']))
{
// check for errors
if(strlen($username) == 0)
$installerrors[] = '请输入系统管理用户名.';
if(strlen($password) == 0)
$installerrors[] = '请输入系统管理密码.';
if($password != $confirmpassword)
$installerrors[] = '管理密码与确认密码不匹配.';
// Determine if MySql is installed
if(function_exists('mysql_connect'))
{
// attempt to connect to the database
if($connection = @MYSQL_CONNECT($servername, $dbusername, $dbpassword))
{
$sqlversion = mysql_get_server_info();
if($sqlversion >= '4.1'){
mysql_query("set names 'gbk'");
}
if($sqlversion > '5.0.1') {
mysql_query("SET sql_mode=''");
}
// connected, now lets select the database
if(!@MYSQL_SELECT_DB($dbname, $connection))
{
// The database does not exist... try to create it:
if(!@DB_Query("CREATE DATABASE $dbname"))
{
$installerrors[] = '数据库 "' . $dbname . '" 不存在.<br />' . mysql_error();
}
else
{
if($sqlversion >= '4.1'){
mysql_query("set names 'gbk'");
}
if($sqlversion > '5.0.1') {
mysql_query("SET sql_mode=''");
}
// Success! Database created
MYSQL_SELECT_DB($dbname, $connection);
}
}
}
else
{
// could not connect
$installerrors[] = '无法连接MySql数据库服务器, 信息:<br />' . mysql_error();
}
}
else
{
// mysql extensions not installed
$installerrors[] = '网站服务器环境不支持MySql扩展.';
}
if(!isset($installerrors))
{
define('TABLE_PREFIX', $tableprefix);
// Drop weenCompany tables for fresh install
DB_Query("DROP TABLE IF EXISTS " . TABLE_PREFIX . "gbconfig");
DB_Query("DROP TABLE IF EXISTS " . TABLE_PREFIX . "guestbook");
DB_Query ("CREATE TABLE " . TABLE_PREFIX . "guestbook (
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(50) NOT NULL DEFAULT '',
content TEXT NOT NULL DEFAULT '',
reply TEXT NULL DEFAULT '',
email VARCHAR(128) NULL DEFAULT '',
userip VARCHAR(22) NOT NULL DEFAULT '',
settop TINYINT(1) NOT NULL DEFAULT 0,
ifshow TINYINT(1) NOT NULL DEFAULT 0,
ifqqh TINYINT(1) NOT NULL DEFAULT 0,
systime DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
replytime DATETIME NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (id)
) ");
DB_Query ("CREATE TABLE " . TABLE_PREFIX . "gbconfig (
id INT(10) UNSIGNED NOT NULL DEFAULT 1,
admin_user VARCHAR(64) NOT NULL DEFAULT '',
admin_pass VARCHAR(64) NOT NULL DEFAULT '',
PRIMARY KEY (id)
) " );
/*
DB_Query ("INSERT INTO " . TABLE_PREFIX . "guestbook VALUES (1,'多多留言本','欢迎使用多多留言本$book_version','','shanshuiboy@163.com','".$_SERVER['REMOTE_ADDR']."',1,1,0, '".date('Y-m-d H:i:s')."','')");*/
DB_Query ("INSERT INTO " . TABLE_PREFIX . "gbconfig VALUES (1,'$username','".md5($password)."') ");
// write config file last off in case installation fails
$configfile="<"."?php
require_once('include/sql_class.php');
\$db=new db_Mysql();
\$db->dbSever = '$servername';
\$db->dbbase = '$dbname';
\$db->dbUser = '$dbusername';
\$db->dbPwd = '$dbpassword';
\$db->dbconnect();
define('MCBOOKINSTALLED', true);
define('TABLE_PREFIX', \"$tableprefix\");
?".">";
//////////////////////////////////
$parafile="<"."?php
\$gb_name = '多多留言本$book_version';
\$gb_logo ='images/logo.gif';
\$index_url = '/';
\$page_ = '10';
\$timejg = '60';
\$replyadmtit = '管理员回复';
\$ifauditing = '0';
?".">";
// write the config file
$filenum = fopen ($rootpath . "include/config.php","w");
ftruncate($filenum, 0);
fwrite($filenum, $configfile);
fclose($filenum);
// write the para file
$filenum = fopen ($rootpath . "include/para.php","w");
ftruncate($filenum, 0);
fwrite($filenum, $parafile);
fclose($filenum);
echo '<font class=ohblue>祝贺您! 多多留言本 '.$book_version.' 已经安装成功!</font><br /><br />请删除安装目录install后继续!
<br /><br />
<a href="' . $rootpath . 'index.php"><b>点击这里浏览留言本!</b></a>';
} // if !isset($installerrors)
}
function DB_Query($sql)
{
$result = MYSQL_QUERY ($sql);
if(!$result)
{
$message = "数据库访问错误\r\n\r\n";
$message .= $sql . " \r\n";
$message .= "错误内容: ". mysql_error() ." \r\n";
$message .= "错误代码: " . mysql_errno() . " \r\n";
$message .= "时间: ".gmdate("l dS of F Y h:i:s A"). "\r\n";
$message .= "文件: http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
echo '<b>数据库访问错误!</b> <br />
<p><form><textarea rows="15" cols="60">'.htmlspecialchars($message).'</textarea></form></p>';
exit;
}
else
{
return true;
}
}
// ############################### INSTALL FORM ################################
if(!isset($_POST['install']) OR isset($installerrors))
{
if(isset($installerrors))
{
echo '<table width="97%" border="0" cellpadding="5" cellspacing="0" align="center">
<tr>
<td style="border: 1px solid #FF0000; font-size: 12px;" bgcolor="#FFE1E1">
<u><b>安装错误!</b></u><br /><br />
安装过程中发现以下错误:<br /><br />';
for($i = 0; $i < count($installerrors); $i++)
{
echo '<b>' . ($i + 1) . ') ' . $installerrors[$i] . '</b><br /><br />';
}
echo ' </td>
</tr>
</table><br /><br />';
}
echo '<table width="96%" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td valign="top"></td>
<td valign="top" align="right" style="padding-bottom: 3px;"><u>中文简体版(GBK)</u></td>
</tr>
</table>
<br />
<b>1) 创建多多留言本数据库:</b><br /><br />
<form method="post" action="install.php" name="installform">
<table width="96%" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td valign="top">数据库服务器地址:</td>
<td valign="top" align="right" style="padding-bottom: 3px;"><input type="text" name="servername" value="' . $servername . '" /></td>
</tr>
<tr>
<td valign="top">数据库名:</td>
<td valign="top" align="right" style="padding-bottom: 3px;"><input type="text" name="dbname" value="' . $dbname . '" /></td>
</tr>
<tr>
<td valign="top">数据用户名:</td>
<td valign="top" align="right" style="padding-bottom: 3px;"><input type="text" name="dbusername" value="' . $dbusername . '" /></td>
</tr>
<tr>
<td valign="top">数据库密码:</td>
<td valign="top" align="right" style="padding-bottom: 3px;"><input type="password" name="dbpassword" size="21"/></td>
</tr>
<tr>
<td valign="top">数据表前缀:</td>
<td valign="top" align="right" style="padding-bottom: 3px;"><input type="text" name="tableprefix" value="' . $tableprefix . '" /></td>
</tr>
</table>
<br /><br />
<b>2) 创建管理员帐号:</b><br /><br />
<table width="96%" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td valign="top">后台管理用户名:</td>
<td valign="top" align="right" style="padding-bottom: 3px;"><input type="text" name="username" value="' . $username . '" /></td>
</tr>
<tr>
<td valign="top">后台管理密码:</td>
<td valign="top" align="right" style="padding-bottom: 3px;"><input type="password" name="password" size="21"/></td>
</tr>
<tr>
<td valign="top">确认管理密码:</td>
<td valign="top" align="right" style="padding-bottom: 6px;"><input type="password" name="confirmpassword" size="21"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="install" value="开始安装留言本" class="submit" /></td>
</tr>
</table>
</form>';
}
// ############################### PRINT FOOTER ################################
echo $footer;
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -