SWG
11-11-2006, 05:01 PM
Let me explain to you what I'm doing here... I'm creating a installation wizard/page for a automated user/member system in PHP (of course). Everything is to be done by the installation wizard so my clients may use it to have their own member system on their Web sites even though they don't know how to code one.
There are three steps of the installation, during these steps, this is what happens:
Step 1.) You enter the path to the directory in which the install file (installation.php) is stored and it CHMOD's it.
Step 2.) You enter your MySQL database information and it writes it to a file (configuration.php). (WHICH REQUIRES CHMOD TO 777!)
Step 3.) The query will run to create the members table in the database. If the query is successful, it will present the form to create the first administrator. If the query is not successful, it will present an error. (I haven't started the third step yet.
Here's the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="author" content="Connor Hart-Bowlan">
<meta name="keywords" content="data, database, install, installaion, system">
<meta name="description" content="The installation page for the CHB Member System.">
<meta name="robots" content="all">
<title>CHB Member System Installation Wizard</title>
<link rel="stylesheet" href="design/css/default.css" type="text/css">
</head>
<body>
<div align="center">
<div id="container">
<?php
if($_GET['step'] == "") {
?>
<div id="content_module">
<h1>Welcome to the CHB Member System Installation Wizard</h1>
<p class="black">Hello, and welcome to the member system's installation wizard (page). Here you will install, setup, and customize your own member system into your Web site!</p>
<div align="right">
<p><a href="?step=1">Continue to the First Step »</a></p>
</div>
</div>
<?php
} elseif($_GET['step'] == "1") {
if(!isset($_POST['submit'])) {
?>
<div id="content_module">
<h1>Installation Step 1: Path Information</h1>
<p class="black">First off, the member system will require the path to all the files for the member system to automatically CHMOD the path given. Please enter the path as it is required for the member system to function.</p>
<form method="post" action="installation.php?step=1">
<input type="text" name="path" size="30">
<input class="submit" type="submit" name="submit" value="Submit">
</form>
<p><i>If you are unsure what your path is, or what a path is, please visit <a href="manual/ii-b.html" target="blank">section II-B</a> of the CHB Member System manual.</i></p>
</div>
<?php
} else {
$path = $_POST['path'];
chmod($path, 0777);
}
} elseif($_GET['step'] == "2") {
if(!isset($_POST['submit2'])) {
?>
<div id="content_module">
<h1>Installation Step 2: Database Information</h1>
<p class="black">Second, the member system will require a database to store all the members in. Please enter and submit this information as it is required for the member system to function.</p>
<form method="post" action="installation.php?step=2">
<table align="center" border=\"0\" cellspacing=\"10\" cellpadding=\"0\">
<tr>
<td width="150">
Database Name:
</td>
<td>
<input type="text" name=\"database_name\" size=\"25\">
</td>
</tr>
<tr>
<td width="150">
Database Host:
</td>
<td>
<input type="text" name="database_host" value="localhost" size=\"25\">
</td>
</tr>
<tr>
<td width=\"150\">
Database User:
</td>
<td>
<input type="text" name="database_user" size="25">
</td>
</tr>
<tr>
<td width=\"150\">
Database User Password:
</td>
<td>
<input type="text" name=\"database_user_password\" size=\"25\">
</td>
</tr>
<tr>
<td width="150">
</td>
<td>
<input class="submit" type="submit" name="submit2" value="Submit">
</td>
</tr>
</table>
</form>
</div>
<?php
} else {
$database_name1 = $_POST['database_name'];
$database_host1 = $_POST['database_host'];
$database_user1 = $_POST['database_user'];
$database_user_password1 = $_POST['database_user_password'];
$file_contents = "<?
\$database_name = \"$name\";
\$database_host = \"$host\";
\$database_user_password = \"$pass\";
\$database_user = \"$user\";
\$connect_db = mysql_connect(\$database_host,\$database_user,\$database_user_password);
mysql_select_db(\$database_name) or die(\'Error: could not connect to database.\');
?>";
$file_open = fopen('configuration.php', 'w');
fwrite($file_open, $file_contents);
fclose($file_open);
}
}
?>
</div>
</div>
</body>
</html>
You can view a temporary upload of the file here: http://www.connorhb.com/installation.php
I've considered changing "chmod($path, 0777);" to "$chmod = chmod($path, 0777);" but I thought I should just ask you people on the forums first.
Thanks in advance.
There are three steps of the installation, during these steps, this is what happens:
Step 1.) You enter the path to the directory in which the install file (installation.php) is stored and it CHMOD's it.
Step 2.) You enter your MySQL database information and it writes it to a file (configuration.php). (WHICH REQUIRES CHMOD TO 777!)
Step 3.) The query will run to create the members table in the database. If the query is successful, it will present the form to create the first administrator. If the query is not successful, it will present an error. (I haven't started the third step yet.
Here's the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="author" content="Connor Hart-Bowlan">
<meta name="keywords" content="data, database, install, installaion, system">
<meta name="description" content="The installation page for the CHB Member System.">
<meta name="robots" content="all">
<title>CHB Member System Installation Wizard</title>
<link rel="stylesheet" href="design/css/default.css" type="text/css">
</head>
<body>
<div align="center">
<div id="container">
<?php
if($_GET['step'] == "") {
?>
<div id="content_module">
<h1>Welcome to the CHB Member System Installation Wizard</h1>
<p class="black">Hello, and welcome to the member system's installation wizard (page). Here you will install, setup, and customize your own member system into your Web site!</p>
<div align="right">
<p><a href="?step=1">Continue to the First Step »</a></p>
</div>
</div>
<?php
} elseif($_GET['step'] == "1") {
if(!isset($_POST['submit'])) {
?>
<div id="content_module">
<h1>Installation Step 1: Path Information</h1>
<p class="black">First off, the member system will require the path to all the files for the member system to automatically CHMOD the path given. Please enter the path as it is required for the member system to function.</p>
<form method="post" action="installation.php?step=1">
<input type="text" name="path" size="30">
<input class="submit" type="submit" name="submit" value="Submit">
</form>
<p><i>If you are unsure what your path is, or what a path is, please visit <a href="manual/ii-b.html" target="blank">section II-B</a> of the CHB Member System manual.</i></p>
</div>
<?php
} else {
$path = $_POST['path'];
chmod($path, 0777);
}
} elseif($_GET['step'] == "2") {
if(!isset($_POST['submit2'])) {
?>
<div id="content_module">
<h1>Installation Step 2: Database Information</h1>
<p class="black">Second, the member system will require a database to store all the members in. Please enter and submit this information as it is required for the member system to function.</p>
<form method="post" action="installation.php?step=2">
<table align="center" border=\"0\" cellspacing=\"10\" cellpadding=\"0\">
<tr>
<td width="150">
Database Name:
</td>
<td>
<input type="text" name=\"database_name\" size=\"25\">
</td>
</tr>
<tr>
<td width="150">
Database Host:
</td>
<td>
<input type="text" name="database_host" value="localhost" size=\"25\">
</td>
</tr>
<tr>
<td width=\"150\">
Database User:
</td>
<td>
<input type="text" name="database_user" size="25">
</td>
</tr>
<tr>
<td width=\"150\">
Database User Password:
</td>
<td>
<input type="text" name=\"database_user_password\" size=\"25\">
</td>
</tr>
<tr>
<td width="150">
</td>
<td>
<input class="submit" type="submit" name="submit2" value="Submit">
</td>
</tr>
</table>
</form>
</div>
<?php
} else {
$database_name1 = $_POST['database_name'];
$database_host1 = $_POST['database_host'];
$database_user1 = $_POST['database_user'];
$database_user_password1 = $_POST['database_user_password'];
$file_contents = "<?
\$database_name = \"$name\";
\$database_host = \"$host\";
\$database_user_password = \"$pass\";
\$database_user = \"$user\";
\$connect_db = mysql_connect(\$database_host,\$database_user,\$database_user_password);
mysql_select_db(\$database_name) or die(\'Error: could not connect to database.\');
?>";
$file_open = fopen('configuration.php', 'w');
fwrite($file_open, $file_contents);
fclose($file_open);
}
}
?>
</div>
</div>
</body>
</html>
You can view a temporary upload of the file here: http://www.connorhb.com/installation.php
I've considered changing "chmod($path, 0777);" to "$chmod = chmod($path, 0777);" but I thought I should just ask you people on the forums first.
Thanks in advance.