自由屋推书网—热门的小说推荐平台!

你的位置: 首页 > php

php制作install程序安装界面

2012-10-23 08:00:53

看到很多网站程序安装都是用install页面来安装,前几天学习制作了php+mysql的留言板,其中的配置文件都是手工打开配置填写的,今天我们简单的分析一下网站程序自动安装的原理!

制作思路:

1、创建填写数据库服务器的基本信息表单;
2、将填写好的数据写入到网站的基本配置文件config.php中;
3、删除安装文件。

建立填写表单的web页面:install.php。代码如下:

=============================================

<html>
<head>
<title>留言板安装</title>
</head>
<body>
<form action="check_install.php" method="POST">
<table>
<tr><td align="right"><font color="Red">*</font> 输入数据库服务器地址:</td><td><input name="llcc_server" type="text" value="localhost"></td></tr>
<tr><td align="right"><font color="Red">*</font> 输入数据库服务器用户名:</td><td><input name="llcc_user_name" type="text" value=""></td></tr>
<tr><td align="right"><font color="Red">*</font> 输入数据库服务器密码:</td><td><input name="llcc_user_pass" type="text" value=""></td></tr>
<tr><td align="right"><font color="Red">*</font> 输入数据库名称:</td><td><input name="llcc_data_name" type="text" value=""> </td></tr>
<tr><td><input type="submit" name="install" value="提交"></td></tr>
</table>
</form>
</body>
</html>

=======================================================

新建一个check_install.php文件,复制以下代码!

=============================================

<?php
//获取提交的数据库值
$llcc_server=$_POST['llcc_server'];
$llcc_user_name=$_POST['llcc_user_name'];
$llcc_user_pass=$_POST['llcc_user_pass'];
$llcc_data_name=$_POST['llcc_data_name'];
//打开数据库配置文件
$fp=fopen("../config.php",'w');
if (!$fp) {
echo "sorry,try again!";
}
//写入文件内容

$outconfig="<?php\n";
$outconfig.='$server=';
$outconfig.="".$llcc_server.";//数据库所在IP,如果是本地,默认localhost\n";
$outconfig.='$server_name=';
$outconfig.="".$llcc_user_name.";//连接数据库用户名,一般为root\n";
$outconfig.='$server_pass=';
$outconfig.="".$llcc_user_pass.";//连接数据库密码。\n";
$outconfig.='$server_data=';
$outconfig.="".$llcc_data_name.";//数据库名\n";
$outconfig.="?>";
$fw=fwrite($fp,$outconfig);
if ($fw) {echo "<br><br><br><center>安装完成!请手动删除目录下install文件夹<br><a href='../'>返回首页</a></center>";}
?>

========================================

如果看过php基础教程的,那么上面的内容应该毫无压力!

由于wordpress会将英文分号自动转换为中文分号,请大家复制后自行修改!

编辑推荐

热门小说