网站安装程序

网站安装程序

1.is_writeable();
2.rename('原名','新名');
3.$resource=fopen($file_path,"w+"),
3.fwrite($resource,$config_str);

目录结构:

install.php代码如下:

<?php
header("Content-Type:text/html;charset=utf-8");
$files_path="./data/config.php";
	if (!is_writeable($files_path)) {
		exit("please check right");
	}else {
		if (isset($_POST['install'])) {
			$config_str="<?php";
			$config_str.="\r\n";
			$config_str.='$mysql_host	=	"'.$_POST['db_host'].'";';
			$config_str.="\r\n";
			$config_str.='$mysql_user	=	"'.$_POST['db_user'].'";';
			$config_str.="\r\n";
			$config_str.='$mysql_pwd	=	"'.$_POST['db_pwd'].'";';
			$config_str.="\r\n";
			$config_str.='$mysql_name	=	"'.$_POST['db_name'].'";';
			$config_str.="\r\n";
			$config_str.='$mysql_tag	=	"'.$_POST['db_tag'].'";';
			$config_str.="\r\n";
			$config_str.="?>";
			$ff=fopen($files_path,"w+");
			fwrite($ff,$config_str);
		}
		require_once './data/config.php';
		if(!@$link=mysql_connect($mysql_host,$mysql_user,$mysql_pwd,$mysql_pwd)){
			echo "数据库连接失败!请返回上一页检查连接参数<a href='install.php'>返回修改</a>";
		}else{
			mysql_select_db($mysql_name);
			$sql_query[]="create table ".$mysql_tag."admin_log1 (
							id int(8) unsigned not null primary key auto_increment,
							username varchar(40) not null,
							types varchar(40) not null);";
			$sql_query[]="create table ".$mysql_tag."admin_log2 (
							id int(8) unsigned not null primary key auto_increment,
							username varchar(40) not null,
							types varchar(40) not null);";
			$sql_query[]="create table ".$mysql_tag."admin_log3 (
							id int(8) unsigned not null primary key auto_increment,
							username varchar(40) not null,
							types varchar(40) not null);";
			foreach ($sql_query as $value){
				mysql_query($value);
			}
			rename("install.php","install.lock");
			echo "<script type='text/javascript'>alert('install is ok');top.location.href='index.php';</script>";
		}	
	}
?>
<html>
<meta http-equiv="Content-Type" content="text/hrml;charset=utf-8" />
<head>
<title>install</title>
</head>
<body>
<form action="?" method="post"><br />
填写主机:<input type="text" name="db_host" value="" /><br />
用 户 名:<input type="text" name="db_user" value="root" /><br />
密   码:<input type="password" name="db_pwd" value="" /><br />
数据库名:<input type="text" name="db_name" value="install" /><br />
数据前缀:<input type="text" name="db_tag" value="p_" /><br />
<!--<input type="submit" name="install" value="install" />-->
<button type="submit" name="install">下一步</button>
</form>
</body>
</html>



转载于:https://my.oschina.net/owengao/blog/166931

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值