Re: [PHP]When making an 'installing' script.
PHP Code:
<? session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
//Check to see if step has already been done
if($_SESSION['step'] == 1 || !isset($_SESSION['step'])) {
if(!isset($_POST['submit'])) {
?>
<form action="<? $_SERVER['PHP_SELF']; ?>" method="post">
Host <input type="text" name="host" />
<br/>
Username <input type="text" name="user" />
<br/>
Password <input type="password" name="pass" />
<br/>
Database <input type="text" name="db" />
<br/>
Title of your blog <input type="text" name="title" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
} else {
$host = $_POST['host'];
$user = $_POST['user'];
$pass = $_POST['pass'];
$db = $_POST['db'];
$title = $_POST['title'];
//Get install directory
$sd = preg_replace("/installer.php/", "", $_SERVER['PHP_SELF']);
if(empty($host) || empty($user) || empty($pass) || empty($_POST['db'])) {
unset($_POST['submit']);
die("Please fill in all the fields.");
}
@mysql_connect($host, $user, $pass) or die ("Could not connect, please check your mysql information.");
@mysql_select_db($_POST['db']) or die ("Invalid database specified");
if(mysql_connect($host, $user, $pass) && mysql_select_db($_POST['db'])) {
//define config.php
$config = '<?php
$host = "'.$host.'";
$user = "'.$user.'";
$pass = "'.$pass.'";
$db = "'.$db.'";
$sd = "'.$sd.'";
$title = "'.$title.'";
?>';
//check if config.php is writable
if($handle = fopen("config.php","w")) {
//write to config.php
fwrite($handle,$config);
fclose($handle);
} else {
die("A fatal error occured, we recommend aborting the installation and starting over from a fresh install. If this error persits consult our troubleshooting.");
}
$_SESSION['step'] = 2;
echo "Step 1 has successfully been completed, proceed to step 2 please.";
echo "<br/><a href='installer.php' target='_self'>Step 2</a>";
}
}
} else if($_SESSION['step'] == 2) {
if(!isset($_POST['submit'])) {
echo "In this step the database will be configured this may take up to 5 minutes. Click the button below to start the configuration."
?>
<form action="<? $_SERVER['PHP_SELF']; ?>" method="post">
<input type="submit" name="submit" value="Configure database" />
</form>
<?php
} else {
//Created tables
mysql_query("CREATE TABLE example(example VARCHAR(255) NOT NULL)");
echo "Step 2 completed, please proceed to step 3.";
echo "<br/><a href='installer.php' target='_self'>Step 3</a>";
$_SESSION['step'] = 3;
}
} else if($_SESSION['step'] == 3) {
if(!isset($_POST['submit']) && !isset($_POST['confirm'])) {
echo "You'll now need to create an admin account. Please do not use any special characters.";
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Username:<br/>
<input type="text" name="uname" maxlength="12"/> (max length 12 characters)<br/>
Password:<br/>
<input type="password" name="passw"/> (min 6 characters)<br/>
Repeat password:<br/>
<input type="password" name="passw2"/><br/>
E-mail:<br/>
<input type="text" name="email"/> (Will be used for password recovery)<br/>
<input type="submit" name="submit" value="submit" />
</form>
<?php
} else {
if(!isset($_POST['confirm'])) {
$_SESSION['uname'] = $_POST['uname'];
$_SESSION['passw'] = $_POST['passw'];
$_SESSION['email'] = $_POST['email'];
echo "Is this information correct?<br/><br/>
Username: ".$_SESSION['uname']."<br/>
Password: ".$_SESSION['passw']."<br/>
E-mail: ".$_SESSION['email']."<br/>
";
?>
<form action="<? $_SERVER['PHP_SELF']; ?>" method="post">
<input type="submit" name="confirm" value="Yes" />
<input type="submit" name="noconfirm" value="No" />
</form>
<?php
} else {
//account creation query here
echo "Installation was successfull. Please delete this file. We hope that your experience with our software will be enjoyable.";
$_SESSION['step'] = 4;
}
}
} else if($_SESSION['step'] == 4) {
echo "Installation is complete, you can now delete this file.";
} else {
echo "You seriously fucked something up.";
}
?>
</body>
</html>
This is the install script I use for my blog, if you use it please use credits.
Re: [PHP]When making an 'installing' script.
Quote:
echo "You seriously fucked something up.";
Nice touch there Pieman :winky:
Anyone know how much server load writting a files takes? And average times of completion?
Re: [PHP]When making an 'installing' script.
Not much, less than writing to a mysql database anyway.
Re: [PHP]When making an 'installing' script.
Quote:
Originally Posted by
Pieman
Not much, less than writing to a mysql database anyway.
That's because MySQL writes it to a file and has additional features which slows it down.
You should keep file reading to a minimum, and read as much as you can in one go (as far as that is possible in PHP).
Re: [PHP]When making an 'installing' script.
I won't be reading from the file, what i will be doing is writing base HTML code into it which will form a page , kinda having to make my own CMS for a group at school.
And this would seem to be the best way i can think of , to allow them to be able to edit pages etc (as they do not know how to change pages/ code / use a FTP client >.<)
Re: [PHP]When making an 'installing' script.
Quote:
Originally Posted by
-fedexer-
I won't be reading from the file, what i will be doing is writing base HTML code into it which will form a page , kinda having to make my own CMS for a group at school.
And this would seem to be the best way i can think of , to allow them to be able to edit pages etc (as they do not know how to change pages/ code / use a FTP client >.<)
That is kind of a bad idea. :x
A better idea would be to have a basic layout and generate the content with another script which you include in the basic layout. That's how I do it with http://pie-designs.net/blog/
Re: [PHP]When making an 'installing' script.
That's what i am doing, i will have a script generate a page like:
Code:
#html here
<?php echo $pageContent; ?>
#finish html
So there will be a standard page layout written to a file, but the content for that page is grabbed from the database.
Either i didn't make myself clear enough, or i didn't quite understand what you ment.
Re: [PHP]When making an 'installing' script.
Yeah that's what I meant. I thought you meant you'd generate a page and then write it to a html file.
Re: [PHP]When making an 'installing' script.
Ah right, nah , sorry for not making myself clear enough.