Location: PHPKode > projects > Openology PHP Application Integration > openology/install/install.php
<?php 
/***************************************************************************
 *   copyright            : (C) 2006 The openology Group
 *   email                : hide@address.com
 *
 *   $Id
 *
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/
header('Content-Type: text/html; charset=UTF-8');
   $script_path = (!empty($HTTP_POST_VARS['script_path'])) ? $HTTP_POST_VARS['script_path'] : str_replace('/install', '', dirname($HTTP_SERVER_VARS['PHP_SELF']));
   $hidd_path = $script_path;
	$dbhost = (!empty($HTTP_POST_VARS['dbhost'])) ? $HTTP_POST_VARS['dbhost'] : 'localhost'; 
function ShowMsg($msg,$gotoPage)
{
	$msg = str_replace("'","`",trim($msg));
	$gotoPage = str_replace("'","`",trim($gotoPage));
	echo "<script language='javascript'>\n";
	echo "alert('$msg');";
	if($gotoPage=="back")
	{
		echo "history.go(-1);\r\n";
	}
	else if(ereg("^-",$gotoPage))
	{
		echo "history.go($gotoPage);\r\n";
	}
	else if($gotoPage!="")
	{
		echo "location.href='$gotoPage';\r\n";
	}
	echo "</script>";
}
$s_isreg = @get_cfg_var("register_globals");
if($s_isreg!=1)
{
	if (!empty($_GET)) foreach($_GET AS $key => $value){$$key = $value;}
	if (!empty($_POST)) foreach($_POST AS $key => $value){$$key = $value;}
}
function GetConfigFile()
{
	$fp = fopen("config_base.php","r") or die("配置文件无法读取或无法访问,请把当前目录权限设为可读写!");
	$configfile = fread($fp,filesize("config_base.php"));
	fclose($fp);
	return $configfile;
}

function SaveConfigFile($str)
{
	$fp = fopen("config_base.php","w") or die("配置文件无法写入,请把当前目录权限设为可读写!");;
	fwrite($fp,$str);
	fclose($fp);
}


if ($step == 1) {
//if(empty($setuptype)) 
    $setuptype=0;

    $conn = @mysql_connect($dbhost,$dbuser,$dbpwd) or die("<script>alert('数据库服务器或登录密码无效,\\n\\n无法连接数据库,请重新设定!');history.go(-1);</script>");
	if($isnew == 1){
    mysql_query("CREATE DATABASE ".$dbname,$conn) or die("<script>alert('创建数据库失败,可能权限不足!');history.go(-1);</script>");;
	}
	mysql_select_db($dbname) or die("<script>alert('数据库不存在,请重新设定!');history.go(-1);</script>");
	//初始化系统表
	$sqlfiles[0]="sql.txt";
	$sql = "INSERT INTO `bbb_user` (`ID`, `ad_name`, `ad_pass`) VALUES (NULL, '$adminname', md5('$adminpwd'));";
	$sqlfile = $sqlfiles[$setuptype];
	$fp = fopen($sqlfile,"r");
	$query = "";
	while($line = fgets($fp,1024))
	{
		$line = trim($line);
		if(ereg(";$",$line))
		{
			$query.=$line;
			mysql_query($query,$conn);
			$query="";
		}
		else if(!ereg("^//",$line))
		{
			$query.=$line;
		}
	}
	fclose($fp);
	if($setuptype==0) mysql_query($sql,$conn);
	//
	mysql_close($conn);

    $basedir = ereg_replace("/$","",$basedir);
	$basedir = str_replace("\\","",$basedir);
	$basepath = ereg_replace("/$","",trim($basepath));
	if($basepath=="/") $basepath="";
	if($basepath!=""&&!ereg("^/",$basepath)) $basepath="/".$basepath;
	$rbasepath = "";
	if($basepath=="") $rbasepath="/";
	else $rbasepath = $basepath;
	if(!file_exists($basedir.$basepath."/install/install.php"))
	{
	/*	echo "<script>alert('网站根目录或相对路径没设置正确!');history.go(-1);</script>";
		exit();*/
	}
	$phpdir = ereg_replace("/$","",$basepath);
	$baktruedir = $phpdir;
	$baseurl = ereg_replace("/$","",$baseurl);
	//$artdir = $basepath.ereg_replace("/$","",$artdir);
	//更改配置文件
	    $configstr = GetConfigFile();
	    $configstr = str_replace("~dbhost~",$dbhost,$configstr);
	    $configstr = str_replace("~dbname~",$dbname,$configstr);
	    $configstr = str_replace("~dbuser~",$dbuser,$configstr);
	    $configstr = str_replace("~dbpwd~",$dbpwd,$configstr);
	    $configstr = str_replace("~basedir~",$basedir,$configstr);
	    $configstr = str_replace("~baseurl~",$baseurl,$configstr);
		$configstr = str_replace("~phpdir~",$hidd_path,$configstr);
		$configstr = str_replace("~indexurl~",$rbasepath,$configstr);
    SaveConfigFile($configstr);

	//if ($need == 1){ 
	copy("config_base.php","../backend/config_base.php");
	copy("login_data.php","../backend/login.php");
	//}
 	ShowMsg("网站安装成功,请将install文件夹删除,确保本程序正常!","../backend/index.php");
}	

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en-EU" lang="en-EU">
<head><title>install</title>
<link rel="stylesheet" href="../backend/css/style.css" type="text/css" />
</head>
<body>
<form action="install.php" name="form1" method="post">
<h3>如果服务器有数据库,请完成以下步骤!如果没有数据库请点击<a href="nodatabase.php">这里</a></h3>
<h4>MySql数据库安装和基本设定</h4><p />
<div id="lwidth">
<div align="right">
<div class="left">数据服务器:</div><input name="dbhost" type="text" id="dbhost" value="<?=$dbhost?>" size="30">
</div>

<div align="right">
<div class="left">数据库名称:</div><input name="dbname" type="text" id="dbname" size="30">
</div>

<div id="note">(要新建数据库请选择创建数据库,数据库名首字符必须为字母)</div>

<div align="right">
  <div class="left">创建数据库:</div><input name="isnew" type="checkbox" id="isnew" value="1">
</div>

<div id="note">(数据库账号与密码)</div>

<div class="clear"></div>
<div align="right">
<div class="left">数据库登录用户:</div><input name="dbuser" type="text" id="dbuser" size="30">
</div>

<div align="right">
<div class="left">数据库登录密码:</div><input name="dbpwd" type="password" id="dbpwd" size="30">
</div>

<div align="right">
<div class="left">管理员名称:</div><input name="adminname" type="text" id="adminname" value="admin">
</div>

<div align="right">
<div class="left">管理员密码:</div><input name="adminpwd" type="text" id="adminpwd" value="admin">
</div>

<div align="right">
<div class="left">平台所在目录:</div><input name="bdir" type="text" id="bdir" value="<?=$script_path?>" size="26" readonly>
</div>

<?php 
    $acpath = @dirname(__FILE__);
	$acpath = str_replace("\\","/",$acpath);
	$acpath = str_replace("$hidd_path/install", "", $acpath); 
?>
<input name="basedir" type="hidden" id="basedir" value="<?=$acpath?>"> 

<div align="right">
<div class="left">域名:</div><input name="baseurl" type="text" id="baseurl" value="<?php if(isset($_SERVER["HTTP_HOST"])) echo $_SERVER["HTTP_HOST"];?>" size="30">
</div>

<!--<div align="right">
<div class="left">使用前台:</div><input type="radio" name="need" value="1" />需要<input type="radio" name="need" value="0" />不需要
</div>-->
</div>
<p />
<div align="center"><input name="step" type="submit" value="完成"></div>
<input type="hidden" name="step" value="1" />
</form>
</body>
</html>
Return current item: Openology PHP Application Integration