程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 創建配置文件 用PHP寫出自己的BLOG系統 2

創建配置文件 用PHP寫出自己的BLOG系統 2

編輯:關於PHP編程

先看看效果圖

創建前文件界面   

創建配置文件後界面,會提示不能重復安裝

下面就上代碼吧,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(\"連接數據庫失敗!\");\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已經存在,要想重新安裝請刪除此文件!<br>";
}
}
?>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved