創(chuàng)建配置文件 用PHP寫出自己的BLOG系統(tǒng) 2
更新時間:2010年04月12日 12:14:04 作者:
今天做博客安裝程序,首先做的是配置文件的創(chuàng)建。
先看看效果圖
<?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,"<"."?php\r\n");
fwrite($fp,"\$host=\"$host\";\r\n");
fwrite($fp,"\$user=\"$user\";\r\n");
fwrite($fp,"\$passwd=\"$passwd\";\r\n");
fwrite($fp,"\$dbname=\"$dbname\";\r\n");
fwrite($fp,"\$sitename=\"$sitename\";\r\n");
fwrite($fp,"\$siteurl=\"$siteurl\";\r\n");
fwrite($fp,"\$sitekeyword=\"$sitekeyword\";\r\n");
fwrite($fp,"\$sitedescription=\"$sitedescription\";\r\n");
$tmp = "\$conn = mysql_connect(\$host,\$user,\$passwd)or die(mysql_error());\r\n";
fwrite($fp,$tmp);
$tmp ="mysql_query(\"set names 'gbk'\")or die(\"設置字符庫失敗!\");\r\n";
fwrite($fp,$tmp);
$tmp ="mysql_select_db(\$dbname,\$conn)or die(\"連接數(shù)據(jù)庫失敗!\");\r\n";
fwrite($fp,$tmp);
fwrite($fp,"?>\r\n");
flock($fp,LOCK_UN);
echo "文件配置成功!<br>";
echo "<script language=\"javascript\">window.location.href=\"install2.php\";</script>";
}
else
{
echo "can't lock the file!<br>";
}
fclose($fp);
$fins = fopen("install_lock.txt","w");
fclose($fins);
}
else
{
echo "install_locak.txt已經(jīng)存在,要想重新安裝請刪除此文件!<br>";
}
}
?>
創(chuàng)建前文件界面

創(chuàng)建配置文件后界面,會提示不能重復安裝

下面就上代碼吧,html界面的代碼就不上了,直接上PHP代碼吧
復制代碼 代碼如下:
<?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,"<"."?php\r\n");
fwrite($fp,"\$host=\"$host\";\r\n");
fwrite($fp,"\$user=\"$user\";\r\n");
fwrite($fp,"\$passwd=\"$passwd\";\r\n");
fwrite($fp,"\$dbname=\"$dbname\";\r\n");
fwrite($fp,"\$sitename=\"$sitename\";\r\n");
fwrite($fp,"\$siteurl=\"$siteurl\";\r\n");
fwrite($fp,"\$sitekeyword=\"$sitekeyword\";\r\n");
fwrite($fp,"\$sitedescription=\"$sitedescription\";\r\n");
$tmp = "\$conn = mysql_connect(\$host,\$user,\$passwd)or die(mysql_error());\r\n";
fwrite($fp,$tmp);
$tmp ="mysql_query(\"set names 'gbk'\")or die(\"設置字符庫失敗!\");\r\n";
fwrite($fp,$tmp);
$tmp ="mysql_select_db(\$dbname,\$conn)or die(\"連接數(shù)據(jù)庫失敗!\");\r\n";
fwrite($fp,$tmp);
fwrite($fp,"?>\r\n");
flock($fp,LOCK_UN);
echo "文件配置成功!<br>";
echo "<script language=\"javascript\">window.location.href=\"install2.php\";</script>";
}
else
{
echo "can't lock the file!<br>";
}
fclose($fp);
$fins = fopen("install_lock.txt","w");
fclose($fins);
}
else
{
echo "install_locak.txt已經(jīng)存在,要想重新安裝請刪除此文件!<br>";
}
}
?>
相關文章
PHP實現(xiàn)的交通銀行網(wǎng)銀在線支付接口ECSHOP插件和使用例子
這篇文章主要介紹了PHP實現(xiàn)的交通銀行網(wǎng)銀在線支付接口ECSHOP插件和使用例子,需要的朋友可以參考下2014-05-05
基于thinkphp5框架實現(xiàn)微信小程序支付 退款 訂單查詢 退款查詢操作
這篇文章主要介紹了基于thinkphp5框架實現(xiàn)微信小程序支付 退款 訂單查詢 退款查詢操作,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-08-08
thinkPHP框架可添加js事件的分頁類customPage.class.php完整實例
這篇文章主要介紹了thinkPHP框架可添加js事件的分頁類customPage.class.php,以完整實例形式給出了分頁類customPage.class.php的實現(xiàn)代碼并分析了ajax動態(tài)加載數(shù)據(jù),設置分頁鏈接等功能,需要的朋友可以參考下2017-03-03

