<?php
error_reporting(0); //不显示错误
ob_start(); //开启输出缓冲
define('ROOT', './'); //定义常量ROOT
$onoff = function_exists('ini_get') ? ini_get('register_globals') : get_cfg_var('register_globals');
if ($onoff != 1) // 允许程序在 register_globals = off 的环境下工作
{
@extract($_POST, EXTR_SKIP); //将变量导入到当前的符号表
@extract($_GET, EXTR_SKIP); //同上
}
function stripslashes_mixed(&$mixed)
{ // 去除转义字符
if (is_array($mixed))
{
foreach ($mixed as $k => $v) // 遍历数组
{
$mixed[$k] = stripslashes_mixed($v); //递归处理
}
}
else
if (is_string($mixed)) // 处理字符串
{
$array = stripslashes($mixed);
}
return $mixed;
}
if (get_magic_quotes_gpc())
{ // 判断 magic_quotes_gpc 状态
$_GET = stripslashes_mixed($_GET); //对GET获得的变量进行处理
$_POST = stripslashes_mixed($_POST); //对POST获得的变量进行处理
}
set_magic_quotes_runtime(0); //设置setting of magic_quotes_runtime ,0 for off, 1 for on
$step = $_GET['step'] ? $_GET['step'] : $_POST['step']; //安装步骤
$php_self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']; //文件本身
$dbcharset = 'utf8'; //设置数据库编码
$configfile = 'config.php'; //定义配置文件
$sqlfile = 'fy.sql'; //定义数据库件
if(!is_readable($sqlfile)) //如果不可读
{
exit('数据库文件不存在或者读取失败');
}
$fp = fopen($sqlfile, 'rb'); //以只读的方式尝试打开
$fsize = filesize($sqlfile); //获取文件字数
$sql = fread($fp, $fsize); //读取数据
fclose($fp); //关闭文件
//程序到此处完成一些初始化,变量定义等,此时页面没有任何输出。首先如果配置文件config.php不存在或者不可写,程序将终止运行并提示错误信息。下面将
//使用定界符输出html
print <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>安装程序</title>
</head>
<body>
<div id="main">
<form method="post" action="$php_self">
<p class="title">安装向导</p>
<hr />
EOT;
if (!$step || $step == '1') //安装的第一步
{
$exist_error = FALSE; //初始化变量
$write_error = FALSE; //初始化变量
if (!file_exists($configfile)) //文件存在
{
$exist_error = TRUE; //exist_error变为ture
}
if (!is_writeable($configfile)) //如果配置文件可写
{
$write_error = TRUE; //write_error变为ture
}
if ($exist_error)
{
Die('config.php 文件不存在, 无法继续.');
}
elseif($write_error)
{
Die('安装向导无法写入配置文件, 请修改配置文件权限.');
}
print <<<EOT
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="30%" nowrap>服务器地址:</td>
<td><input type="text" value="" name="servername" class="formfield" style="width:150px"> 一般是 localhost</td>
</tr>
<tr>
<td width="30%" nowrap>数据库名:</td>
<td><input type="text" value="" name="dbname" class="formfield" style="width:150px"></td>
</tr>
<tr>
<td width="30%" nowrap>数据库用户名:</td>
<td><input type="text" value="" name="dbusername" class="formfield" style="width:150px"></td>
</tr>
<tr>
<td width="30%" nowrap>数据库用户密码:</td>
<td><input type="password" value="" name="dbpassword" class="formfield" style="width:150px"></td>
</tr>
<tr>
<td width="30%" nowrap>数据表前缀:</td>
<td><input type="text" value="" name="db_prefix" class="formfield" style="width:150px"> 不填则默认是 fy_</td>
</tr>
</table>
<hr />
<p align="right">
<input type="hidden" name="step" value="2" />
<input class="formbutton" type="submit" value="下一步" />
</p>
EOT;
}
elseif ($step == '2')
{
if(trim($_POST['dbname']) == "" || trim($_POST['servername']) == "" || trim($_POST['dbusername']) == "")
{
print <<<EOT
<p>请返回并确认所有选项均已填写.</p>
<hr />
<p align="right">
<input class="formbutton" type="button" value="上一步" onclick="history.back(1)" />
</p>
EOT;
}
else
{ //如果都已经填写完整了
if(is_writeable($configfile)) //配置文件可写
{
$servername = trim($_POST['servername']); //去掉空格
$dbusername = trim($_POST['dbusername']); //同上
$dbpassword = trim($_POST['dbpassword']); //同上
$dbname = trim($_POST['dbname']); //同上
$db_prefix = trim($_POST['db_prefix']); //同上
$db_prefix = $db_prefix ? $db_prefix : 'fy_'; //表前缀没有填写则默认为fy_
$fp = @fopen($configfile, 'r'); //只读的方式打开
$filecontent = @fread($fp, @filesize($configfile));//读取内容
@fclose($fp); //关闭
$filecontent = preg_replace("/[$]servername\s*\=\s*[\"'].*?[\"']/is", "\$servername = '$servername'", $filecontent); //正则替换servername的值为新值
$filecontent = preg_replace("/[$]dbusername\s*\=\s*[\"'].*?[\"']/is", "\$dbusername = '$dbusername'", $filecontent); //正则替换dbusername
$filecontent = preg_replace("/[$]dbpassword\s*\=\s*[\"'].*?[\"']/is", "\$dbpassword = '$dbpassword'", $filecontent); //正则替换dbpassword
$filecontent = preg_replace("/[$]dbname\s*\=\s*[\"'].*?[\"']/is", "\$dbname = '$dbname'", $filecontent); //正则替换dbname
$filecontent = preg_replace("/[$]db_prefix\s*\=\s*[\"'].*?[\"']/is", "\$db_prefix = '$db_prefix'", $filecontent); //正则替换表前缀
$fp = @fopen($configfile, 'w'); //可写,覆盖的方式打开,w+为追加
@fwrite($fp, trim($filecontent)); //写入新的内容
@fclose($fp); //再次关闭文件
}
include ($configfile); //包含配置文件,并使用它连接数据库
include ('include/func_db_mysql.php'); //包含数据库操作类
$DB = new DB_MySQL; //创建一个新的数据库对象
$DB->connect($servername, $dbusername, $dbpassword, $dbname, $usepconnect);
unset($servername, $dbusername, $dbpassword, $usepconnect);//销毁变量
$msg = ''; //初始化
$quit = FALSE; //初始化
$curr_php_version = PHP_VERSION; //PHP的版本
if($curr_php_version < '4.0.6')
{
$msg .= "<font color=\"#FF0000\">您的PHP版本低于4.0.6, 无法使用本程序</font><br />";
$quit = TRUE;
}
$query = $DB->query("SELECT VERSION()"); //查询mysql版本信息
$curr_mysql_version = $DB->result($query, 0);
if($curr_mysql_version < '3.23')
{ //mysql版本< 3.23
$msg .= "<font color=\"#FF0000\">您的MySQL版本低于3.23, 由于程序没有经过此平台的测试, 建议您换 MySQL4 的数据库服务器.</font><br />";
$quit = TRUE;
}
if(strstr($db_prefix, '.'))
{
$msg .= "<font color=\"#FF0000\">您指定的数据表前缀包含点字符,请返回修改.</font><br />";
$quit = TRUE;
}
$DB->select_db($dbname);
if($DB->geterrdesc())
{
if(mysql_get_server_info() > '4.1')
{
$DB->query("CREATE DATABASE $dbname DEFAULT CHARACTER SET $dbcharset");
}
else
{
$DB->query("CREATE DATABASE $dbname");
}
if($DB->geterrdesc())
{
$msg .= "<font color=\"#FF0000\">指定的数据库不存在, 系统也无法自动建立, 无法安装</font><br />";
$quit = TRUE;
}
else
{
$DB->select_db($dbname);
$msg .= "成功建立指定数据库<br />";
}
}
$query - $DB->query("SELECT COUNT(*) FROM {$db_prefix}s
没有合适的资源?快使用搜索试试~ 我知道了~
php程序自动安装实例
共4个文件
php:3个
sql:1个
需积分: 9 13 下载量 174 浏览量
2010-04-20
16:23:12
上传
评论
收藏 38KB RAR 举报
温馨提示
通过这个实例你可以很清楚明白很多php系统是如何自动安装的,就算不明白直接使用也挺好用的。
资源推荐
资源详情
资源评论
收起资源包目录
ym_install.rar (4个子文件)
ym_install
include
func_db_mysql.php 4KB
install.php 10KB
config.php 239B
fy.sql 169KB
共 4 条
- 1
资源评论
moliyishengyuan
- 粉丝: 31
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功