Location: PHPKode > projects > l2jweb > install/install.php
<?
error_reporting(E_ALL);
require_once ('../smarty_libs/Smarty.class.php');
$smarty = new Smarty;
$smarty->compile_dir = '../temp/template_c/';
$smarty->config_dir = '../temp/configs/';
$smarty->template_dir = 'skin';

function install(){
//create config file
$config_file = ' <?
';
$config_file .= "define('DBHOST', '".$_POST['DBHOST']."');\n";
$config_file .= "define('DBUSER', '".$_POST['DBUSER']."');\n";
$config_file .= "define('DBNAME', '".$_POST['DBNAME']."');\n";
$config_file .= "define('DBPASS', '".$_POST['DBPASSWORD']."');\n";
$config_file .= '?>';
if ($conf_id = fopen ('../db.inc.php', 'x')){
	fwrite($conf_id, $config_file);
	fclose($conf_id);
	}
else echo nl2br("You will need to modify this to your db.inc.php file:\n ".htmlentities($config_file));

$file_id = fopen ('my.sql', 'r');
$sql_cont = fread($file_id, filesize('my.sql'));
fclose($file_id);
$sql_cont = str_replace('l2jserver', $_POST['DBNAME'], $sql_cont);
$sql_cont = str_replace('127.0.0.1', $_SERVER['REMOTE_ADDR'], $sql_cont);
$sql_cont1 = explode(';' ,$sql_cont);
foreach ($sql_cont1 as $key => $value)
	{
		mysql_query($value);
	}

$sql = "INSERT INTO `web_accounts` ( `id` , `username` ,`email`, `password` , `ip_reg` , `date-register`, `validation_code`, `accesslevel` ) VALUES (NULL, '" .
            htmlentities($_POST['username']) . "', '" . $_POST['email'] . "','" .
            base64_encode(pack('H*', sha1(utf8_encode($_POST['passwd'])))) . "', '" . $_SERVER['REMOTE_ADDR'] .
            "', NOW( ), '" . md5(htmlentities($_POST['username']) . base64_encode(pack('H*',
            sha1(utf8_encode($_POST['passwd']))))) . "', 100);";
mysql_query($sql);
$sql = "INSERT INTO `accounts` ( `login` , `password` , `lastactive` , `access_level` , `lastIP` , `lastServer` )
VALUES (
'" . htmlentities($_POST['username']) . "', '" . base64_encode(pack('H*', sha1(utf8_encode($_POST['passwd'])))) . "', 0, '0', '" . $_SERVER['REMOTE_ADDR'] .
        "', '1'
);";
mysql_query($sql);
}


$err_msg = '';
if (!isset($_GET['page'])) $_GET['page']='start';
switch ($_GET['page']){
	case 'start':$smarty->display('main.tpl'); break;
	case 'step1':
		if (@mysql_connect($_POST['DBHOST'], $_POST['DBUSER'], $_POST['DBPASSWORD'])){
				if (@!mysql_select_db($_POST['DBNAME']))
					{
						$err_msg .= 'Could not select the specified database!';
					} 
			}
		else 
			{
				$err_msg .= 'Could not connect to the DB server!';
			}
	if ($err_msg=='') { install();echo 'App installed!';}
		else {
		$smarty->assign('ERROR_MSG',$err_msg);
		$smarty->display('main.tpl');
		}
	break;

	}
	
	
?>
Return current item: l2jweb