PDA

View Full Version : Creating an Installation System. How?


SDP2006
06-28-2004, 10:00 PM
How can I achieve this? My configuration file looks something like this<?php

define('DB','test');
define('DB_USER','root');
define('DB_PASS','rootpass');
define('DB_TABLE','announcements');

define('USERNAME','Admin');
define('PASSWORD','1234');
define('SITE_NAME','Cannon');

$link = mysql_connect("localhost",DB_USER,DB_PASS) or die(mysql_error());
mysql_select_db(DB,$link) or die(mysql_error());

?> I want the user to see a form, and these 'definitions' will be updated according the the form. I'm doing this so it will be easier for users to install.

When the install is run, it sets the definitions of them according to the form at installation.

All help is welcome.

Thanks.

Stevie

Nightfire
06-28-2004, 10:24 PM
Easiest way... save the username, password etc as variables into a file. Then just include the file at the top.

SDP2006
06-29-2004, 12:55 AM
Thanks, that worked. Here it is. :)<?php

if(isset($_POST['submit']))
{
echo "<strong>Installation Progress...</strong><br />";
$handle = fopen("configuration.php","w+");
$file_contents = "<?php

define('DB','".$_POST['db_name']."');
define('DB_USER','".$_POST['db_user']."');
define('DB_PASS','".$_POST['db_pass']."');
define('DB_TABLE','".$_POST['db_table']."');

define('USERNAME','".$_POST['username']."');
define('PASSWORD','".$_POST['password']."');
define('SITE_NAME','".$_POST['sitename']."');

require('cnx.php');

?>";

echo "<ol>";
fwrite($handle,$file_contents);
fclose($handle);
echo "<li>configuration.php file creation complete!</li>";

require('configuration.php');

$query = "CREATE TABLE `".DB_TABLE."`(
`id` mediumint(9) NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '0',
`date` varchar(255) NOT NULL default '0',
`announcement` text NOT NULL,
PRIMARY KEY (`id`));";
mysql_query($query) or die(mysql_error());
mysql_close($link);

echo "<li>MySQL Database table '".DB_TABLE."' created.</li></ol>";
echo '<strong>Congratulations! Installation is complete!</strong><br /> You may now proceed to the <a href="index.php">administration panel</a> using the <strong>username:</strong> '.USERNAME.' and <strong>password:</strong> '.PASSWORD.'<br />For security reasons, please delete <strong>install.php</strong> after proceeding to the administration panel.';

}
?>
Thanks.