PHP 系统安装文件(install.php)

<?php
 if(isset($_POST["Submit"]))
 {
  $mydbuser = $_POST["m_root"];
  $mydbpw = $_POST["m_pw"];
  $mydbname = $_POST["m_db"];
  $Admin_Name = $_POST["Admin_Name"];
  $Admin_Pwd = md5($_POST["Admin_Pwd"]);
  if(!@mysql_connect("localhost",$mydbuser,$mydbpw))
  {
   echo "<script>alert('mysql用户名或密码不正确!')</script>";
  }
  mysql_query("set names 'gbk'");
  $dbsql = "CREATE DATABASE IF NOT EXISTS ".$mydbname;
  if(!@mysql_query($dbsql))
  {
   echo "<script>alert('请检查是否有建数据库的权限!')</script>";
  }
  echo "<script>alert('数据库创建成功!')</script>";
  mysql_select_db($mydbname);
  $char = '';
  if(mysql_get_server_info()> '4.1') $char = 'DEFAULT CHARSET=gbk';
  $sql = "CREATE TABLE `Admin` (
  `Admin_Id` int(255) unsigned NOT NULL auto_increment,
    `Admin_Name` varchar(20),
    `Admin_Pwd` mediumtext,
    PRIMARY KEY  (`Admin_Id`)
  ) ENGINE=MyISAM {$char};";
  if(!@mysql_query($sql))
  {
   echo "<script>alert('请检查数据表 Admin 是否已存在,存在请先删除!')</script>";
  }
  echo "<script>alert('创建数据表 Admin 成功!')</script>";
  
  $sql = "INSERT INTO `Admin` VALUES (1, '$Admin_Name', '$Admin_Pwd')";
  if(@mysql_query($sql)){echo "<script>alert('初始化数据表成功!')</script>";}
  //$sql = "CREATE TABLE `reply` (
//  `r_id` int(255) unsigned NOT NULL auto_increment,
//  `p_id` int(255) NOT NULL,
//  `r_content` varchar(255) NOT NULL,
//  `r_rname` varchar(20) NOT NULL,
//  `r_time` date NOT NULL,
//  PRIMARY KEY  (`r_id`),
//  UNIQUE KEY `p_id` (`p_id`)
//) ENGINE=MyISAM {$char};";
//if(!@mysql_query($sql)){echo "请检查数据表reply是否存在,存在请先删除.";exit;}
//echo "创建数据表 reply 成功>><br>";
  $str = '<?php'."\n";
  $str .= '$mydbhost = \'localhost\''.";//数据库服务器\n";
  $str .= '$mydbuser = \''.$mydbuser."';//数据库用户名\n";
  $str .= '$mydbpw = \''.$mydbpw."';//数据库密码\n";
  $str .= '$mydbname = \''.$mydbname."';//数据库名\n";
  $str .= '$mydbcharset = \'gbk\''.";//数据库编码,不建议修改.\n";
  $str .= '$Admin_Name = \''.$Admin_Name.'\';//管理员名称'."\n";
  $str .= '$Admin_Pwd = \''.$Admin_Pwd.'\';//管理员密码'."\n";
  $str .= '$eachpage = 5;//每页显示留言条数'."\n";
  $str .= '?>';
  
  $fp = fopen('config.php','w');
  if(!$fp)
  {
   echo"<script>alert('此空间不支持file函数,请手动配置config.php上的内容!')</script>";
  }
  else
  {
   fwrite($fp,$str);
   fclose($fp);
   echo "<script>alert('配置文档 config.php 更新成功!')</script>";
   echo "<script>alert('安装顺利完成.安全起见,请删除insall.php!')</script>";
  }
  echo '<a href="index.php">进入留言板首页</a>';
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>网站管理系统安装</title>
<link type="text/css" href="guest.css" rel="stylesheet">
</head>
<body>
<center>
<table id="ptable" class="tableboder" cellpadding="0" cellspacing="1">
<form id="form1" name="form1" method="post" action="">
  <tr>
    <td colspan="3" class="header">安装网站管理系统</td>
    </tr>
  <tr>
    <td>数据库服务器:</td>
    <td><input name="m_host" type="text" id="m_host" value="localhost"></td>
    <td>数据库服务器地址, 一般为 localhost</td>
  </tr>
  <tr>
    <td width="220">数据库用户名:</td>
    <td width="266"><input name="m_root" type="text" id="m_root" /></td>
    <td width="280">数据库账号用户名</td>
  </tr>
  <tr>
    <td>数据库密码:</td>
    <td><input name="m_pw" type="password" id="m_pw" /></td>
    <td>数据库账号密码</td>
  </tr>
  <tr>
    <td>数据库名:</td>
    <td><input name="m_db" type="text" id="m_db"></td>
    <td> 不存在自动创建</td>
  </tr>
  <tr>
    <td>留言板管理员名:</td>
    <td><input name="Admin_Name" type="text"></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>留言板管理员密码:</td>
    <td><input name="Admin_Pwd" type="text"></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><input type="submit" name="Submit" value=" 安 装 " />
      &nbsp;&nbsp;安装后所以配置可以在 include/config.php再作修改</td>
    </tr>
</form>
</table>
</center>
</body>
</html>

发表评论