欢迎来到福编程网,本站提供各种互联网专业知识!

创建配置文件 用PHP写出自己的BLOG系统 2

发布时间:2010-04-12 作者: 来源:转载
今天做博客安装程序,首先做的是配置文件的创建。
先看看效果图

创建前文件界面

创建配置文件后界面,会提示不能重复安装

下面就上代码吧,html界面的代码就不上了,直接上PHP代码吧
复制代码 代码如下:
/*
FILE:install.php
Author:www.5dkx.com
DATE:2010-3-29
DONE:安装配置文件
*/
if($_POST[mysubmit])
{
$host = $_POST[hostname];
$user = $_POST[user];
$passwd = $_POST[passwd];
$dbname = $_POST[dbname];
$siteurl = "http://".$_POST[siteurl];
$sitekeyword = $_POST[sitekeyword];
$sitedescription = $_POST[sitedescription];
$sitename = $_POST[sitename];
if(!file_exists("install_locak.txt"))
{
$fp = fopen("./include/config.func.php","w+");
if(flock($fp,LOCK_EX))
{
fwrite($fp,"<"."?phprn");
fwrite($fp,"$host="$host";rn");
fwrite($fp,"$user="$user";rn");
fwrite($fp,"$passwd="$passwd";rn");
fwrite($fp,"$dbname="$dbname";rn");
fwrite($fp,"$sitename="$sitename";rn");
fwrite($fp,"$siteurl="$siteurl";rn");
fwrite($fp,"$sitekeyword="$sitekeyword";rn");
fwrite($fp,"$sitedescription="$sitedescription";rn");
$tmp = "$conn = mysql_connect($host,$user,$passwd)or die(mysql_error());rn";
fwrite($fp,$tmp);
$tmp ="mysql_query("set names 'gbk'")or die("设置字符库失败!");rn";
fwrite($fp,$tmp);
$tmp ="mysql_select_db($dbname,$conn)or die("连接数据库失败!");rn";
fwrite($fp,$tmp);
fwrite($fp,"?>rn");
flock($fp,LOCK_UN);
echo "文件配置成功!

";
echo "";


}
else
{
echo "can't lock the file!

";
}
fclose($fp);
$fins = fopen("install_lock.txt","w");
fclose($fins);
}
else
{
echo "install_locak.txt已经存在,要想重新安装请删除此文件!

";
}
}
?>

相关推荐