Hey Leute,
ich habe ja schon mal ein Tut zu einem Installationsscript geschrieben. Nun möchte ich eine komplett neue und noch einfachere Art eines PHP-Mysql-Installationsscript veröffentlichen.
Wie kann ich dort eine Checkbox einbauen, bei dem steht, "Did you read the License Agreement?". Wenn ja, dann sollte er den Script ausführen. Wenn nein, dann nicht. Per Pop-Up sollte die AGB dann geöffnet werden können.
Außerdem werde ich noch die Passwörter verschüsseln und den Tabellen-Präfix einbauen. Aber das lasst mal meine Sorgen sein.
Danke schon mal im Vorraus.
Matze
ich habe ja schon mal ein Tut zu einem Installationsscript geschrieben. Nun möchte ich eine komplett neue und noch einfachere Art eines PHP-Mysql-Installationsscript veröffentlichen.
PHP:
<!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=utf-8" />
<title>MatzeCMS Install</title>
<style type="text/css">
<!--
#main {
margin-right: auto;
margin-left: auto;
width: 950px;
}
body {
margin: 0px;
padding: 0px;
background-color: #666;
color: #eeeeee;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
input {
background-color: #eeeeee;
border: 1px solid #9FC54E;
color: #666;
font-size: 14px;
padding:4px;
}
strong {
color: #9FC54E;
border-bottom-width: 1px;
border-bottom-style: dotted;
border-bottom-color: #9FC54E;
display: block;
margin-top: 10px;
font-size: 18px;
line-height: 30px;
}
.success {
cursor:pointer;
height: 50px;
text-indent: 55px;
margin: 5px;
line-height: 50px;
padding: 5px;
background-position: 5px;
font-size: 16px;
width: 700px;
border:1px solid #739F1D;
background-color: #D4F684;
background-image: url(admin/images/tick.png);
background-repeat: no-repeat;
display:block;
color: #333;
}
.warning {
height: auto;
color:#333;
text-indent: 55px;
margin: 5px;
line-height: 50px;
padding: 5px;
background-position: 5px;
font-size: 16px;
width: 700px;
border:1px solid #F1AA2D;
background-color: #FEFFC8;
background-image: url(admin/images/alert.png);
background-repeat: no-repeat;
display:block;
cursor:pointer;
}
-->
</style>
</head>
<body>
<div id='main'>
<?php
if ($_POST)
{
$error = "";
$db_host = $_POST['host'];
$db_username = $_POST['username'];
$db_password = $_POST['password'];
$db_name = $_POST['db'];
$site_name = $_POST['name'];
$site_keywords = $_POST['keywords'];
$site_description = $_POST['description'];
$site_seo = $_POST['seo'];
$site_username = $_POST['site_username'];
$site_password = md5($_POST['site_password']);
$site_email = $_POST['site_email'];
$site_url = $_POST['site_url'];;
$config = fopen("config.php", 'a');
$contents = '<?php
$db[\'host\'] = \''. $db_host . '\';
$db[\'username\'] = \''. $db_username . '\';
$db[\'password\'] = \''. $db_password . '\';
$db[\'name\'] = \''. $db_name . '\';
?>';
$write = fwrite($config, $contents);
if ($write)
{
fclose($config);
} else
{
$error .= "<div class='warning'>Failed to write to config file.</div>";
}
$mysql_con = @mysql_connect($db_host,$db_username,$db_password);
if (!$mysql_con) {
$error .= "<div class='warning'>Unable to connect to mysql.</div>";
}
$mysql_db = @mysql_select_db($db_name);
if (!$mysql_db) {
$error .= "<div class='warning'>Unable to select database.</div>";
}
$sql[1] = "CREATE TABLE IF NOT EXISTS `pages` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`content` text NOT NULL,
`title` varchar(455) NOT NULL,
`menu_title` varchar(255) NOT NULL,
`show_in_menu` int(10) NOT NULL,
`keywords` varchar(455) NOT NULL,
`description` varchar(455) NOT NULL,
`date` datetime NOT NULL,
`modified` varchar(100) NOT NULL,
`active` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=28 ;";
$sql[2] = "CREATE TABLE IF NOT EXISTS `blocks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`content` text NOT NULL,
`description` varchar(455) NOT NULL,
`name` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=28 ;";
$sql[3] = "
CREATE TABLE IF NOT EXISTS `settings` (
`name` varchar(255) NOT NULL,
`keywords` varchar(255) NOT NULL,
`description` varchar(500) NOT NULL,
`seo_url` int(3) NOT NULL,
`template` varchar(50) NOT NULL,
`site_url` varchar(255) NOT NULL,
`filemanager_default_directory` varchar(455) NOT NULL,
`language` varchar(50) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
";
$sql[4] = "CREATE TABLE IF NOT EXISTS `users` (
`id` int(50) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`email` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
$sql[5] = "CREATE TABLE IF NOT EXISTS `log` (
`username` varchar(455) NOT NULL,
`info` varchar(455) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
$sql[6] = "INSERT INTO `settings` (`name`, `keywords`, `description`, `seo_url`, `template`, `site_url`, `filemanager_default_directory`) VALUES
('$site_name', '$site_keywords', '$site_description', $site_seo, 'templates/default', '$site_url', 'files/');";
$sql[7] = "INSERT INTO `pages` (`id`, `content`, `title`, `menu_title`, `show_in_menu`, `keywords`, `description`, `date`, `modified`, `active`) VALUES
(1, 'Please go to admin section to edit this page', 'Homepage', 'Home', 1, '', '', '2010-02-03 22:21:26', '', 0);
";
$sql[8] = "INSERT INTO `pages` (`id`, `content`, `title`, `menu_title`, `show_in_menu`, `keywords`, `description`, `date`, `modified`, `active`) VALUES
(2, 'Please go to admin section to edit this page', 'Demo Page', 'Demo Page', 1, '', '', '2010-02-03 22:21:26', '', 0);
";
$sql[9] = "INSERT INTO `users` (`username`, `password`, `email`) VALUES
('$site_username', '$site_password', '$site_email');";
$sql[10] = "INSERT INTO `blocks` (`id`, `content`, `description`, `name`) VALUES
('1', '
<div id=\'block\'>
<div id=\'block_heading\'>This is a sample block</div>
You can Edit, Create and Delete blocks in the <a href=\'admin/?action=blocks\'>manage blocks</a>
section in the admin.
</div>
', 'Outputs a demo block', 'my first block');";
for ($i=1; $i<=10; $i++)
{
$q = mysql_query($sql[$i]);
if (!$q)
{
$m_error = mysql_error();
$error .= "<div class='warning'>Error in mysql query $i.<br>$m_error</div>";
}
}
if (empty($error))
{ ?>
<div class="success">Success! - MatzeCMS has been successfully installed - visit the admin <a href="admin/">Here</a>.</div>
<?php } else
{ ?>
<div class="warning"> Error has occured - Please check settings</div>
<?=$error?>
<?php }
} else
{
?>
<form id="form1" name="form1" method="post" action="">
<table width="953" border="0">
<tr>
<td width="240"><h3><strong>Mysql Database Settings</strong></h3></td>
<td width="673"> </td>
</tr>
<tr>
<td>Host</td>
<td><input name="host" type="text" value="localhost" /></td>
</tr>
<tr>
<td>Username</td>
<td><input type="text" name="username" id="username" /></td>
</tr>
<tr>
<td>Password</td>
<td><input name="password" type="text" /></td>
</tr>
<tr>
<td>Database Name</td>
<td><input name="db" type="text" id="db" /> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><h3><strong>Website Settings</strong></h3></td>
<td> </td>
</tr>
<tr>
<td>Website URL</td><?php $full_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$full_url = str_replace("install.php","", $full_url);?>
<td><input name="site_url" type="text" id="site_url" value="<?=$full_url?>" size="50" /></td>
</tr>
<tr>
<td>Admin Username</td>
<td><input name="site_username" type="text" size="50" id="site_username" /></td>
</tr>
<tr>
<td>Admin Password</td>
<td><input name="site_password" type="text" size="50" id="site_password" /></td>
</tr>
<tr>
<td>Admin Email</td>
<td><input name="site_email" type="text" size="50" id="site_email" /></td>
</tr>
<tr>
<td>Website Name</td>
<td><input name="name" type="text" size="50" /></td>
</tr>
<tr>
<td>Website Description</td>
<td><input name="description" type="text" size="50" /></td>
</tr>
<tr>
<td>Website Keywords</td>
<td><input name="keywords" type="text" size="50" /></td>
</tr>
<tr>
<td>Turn on SEO urls</td>
<td><p>
<label>
<input type="radio" name="seo" value="1" id="RadioGroup1_0" />
Yes</label><br />
<label>
<input type="radio" name="seo" value="0" id="RadioGroup1_1" />
No</label><br />
</p></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="submit" id="submit" value="Install" onclick="confirm('Are you sure everything is right?')" />
</label></td>
</tr>
</table>
</form>
<?php } ?>
</div>
</body>
</html>
Außerdem werde ich noch die Passwörter verschüsseln und den Tabellen-Präfix einbauen. Aber das lasst mal meine Sorgen sein.
Danke schon mal im Vorraus.
Matze