In this article, we are going to write our install.php page. Install.php is going to actually get all of the information from our user, such as database, username, password, admin setup, etc.
This is vital to our script if we want to have a script that we can mass produce. The install page is going to do quite a few things. First, it will create the database. It will also write the site configuration page that will be detrimental to our site’s existence because the site will rely on this page for connection details along with details for our SEO. This script is also going to create our .htaccess file that will be used to make SEO friendly URL’s.
Prior to doing this, let’s go ahead and create a file system on our local machine to run this code from. We will need to make the parent folder and name it what you will. Inside that folder, let’s create our children folders: ->admin, ->inc, ->install, ->media, ->template. We will come back to these folders later and add more folders to these but for now this is going to be our main file structure.
Open your php editor, and get ready to write the install file. You can go ahead and save the file into the install folder as index.php.
<?php session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>phpPig Content Management and Shopping Cart Script</title>
</head>
<body style="background-image:url(bg.gif);">
<br>
<br>
<br>
<center>
<img src="top.png">
<div style="border:1px #8EB9FF solid; border-left:1px #8EB9FF solid; border-right:1px #8EB9FF solid; width:293px;" align="center">
<?
if(!isset($_REQUEST['page'])){
?>
<form action="index.php?page=2" method="post" style="display:inline;">
<table cellpadding="0" border="0" style="border-collapse: collapse" width="260">
<tr>
<td colspan="2" valign="middle" align="center">
<br>
Step 1: MySql Information
<br>
<br>
</td>
</tr>
<tr>
<td>Mysql Host Name</td>
<td><input type="text" value="localhost" name="host" size="15" value="localhost"></td>
</tr>
<tr>
<td>Mysql Database</td>
<td><input type="text" name="dbtable" size="15"></td>
</tr>
<tr>
<td>Mysql User Name</td>
<td><input type="text" name="dbname" size="15"></td>
</tr>
<tr>
<td>Mysql Password</td>
<td><input type="password" name="dbpass" size="15"></td>
</tr>
<tr>
<td>Table Prefix</td>
<td><input type="text" name="prefix" size="15" value="ShoppingCartDeluxe"></td>
</tr>
<tr>
<td>Site Description</td>
<td><input type="text" name="desc" size="15" value="Your Site Description"></td>
</tr>
<tr>
<td>Site Keywords</td>
<td><input type="text" name="key" size="15" value="Your Keywords Here"></td>
</tr>
<tr>
<td>
Shopping Cart SEO extension<br/>
i.e. site.com/<i><b>products</b>/</i>
</td>
<td>
<input name="cart" type="text" size="15" value="products"/>
</td>
</tr>
<tr>
<td>
Blog SEO extension<br/>
i.e. site.com/<i><b>blog</b></i>/
</td>
<td>
<input name="seo" type="text" size="15" value="blog"/>
</td>
</tr>
<tr><td colspan="2" align="right"><input type="submit" name="submit" value="Submit"><br /><br /></td></tr>
</table>
</form>
<?
}
if ($_REQUEST['page'] == 2)
{
$_SESSION['host'] = $_POST['host'];
$_SESSION['cart'] = $_POST['cart'];
$_SESSION['dbname'] = $_POST['dbname'];
$_SESSION['dbtable'] = $_POST['dbtable'];
$_SESSION['dbpass'] = $_POST['dbpass'];
$_SESSION['prefix'] = $_POST['prefix'];
$_SESSION['seo'] = $_POST['seo'];
$_SESSION['desc'] = $_POST['desc'];
$_SESSION['key'] = $_POST['key'];
$con = @mysql_connect ($_SESSION['host'],$_SESSION['dbname'], $_SESSION['dbpass']) or die ("<br>Can not make the connection to the database.<br><br> <a href='index.php'>Click here to enter connection details.</a><br><br>");
$db = @mysql_select_db ($_SESSION['dbtable'],$con) or die ("<br>Can not connect to database. <br><br> <a href='index.php'>Click here to enter connection details.</a><br><br>");
mysql_query("CREATE TABLE `".$_SESSION['prefix']."_cats` ( `id` int(10) unsigned NOT NULL auto_increment, `name` text NOT NULL, `keywords` text NOT NULL, `description` text NOT NULL, `parentid` tinyint(4) NOT NULL default '0', PRIMARY KEY (`id`) );");
mysql_query("INSERT INTO `".$_SESSION['prefix']."_cats` VALUES(1, 'News', '', '', 0);");
mysql_query("CREATE TABLE ".$_SESSION['prefix']."_storecat (`id` int(10) unsigned NOT NULL auto_increment, `name` text NOT NULL, `description` text NOT NULL, `keywords` text NOT NULL, PRIMARY KEY (`id`));");
mysql_query("INSERT INTO ".$_SESSION['prefix']."_storecat VALUES(1,'Products','','');");
mysql_query("CREATE TABLE ".$_SESSION['prefix']."_items (`id` int(10) unsigned NOT NULL auto_increment, `title` text NOT NULL, `author` text NOT NULL, `price` decimal(5,2) NOT NULL, `image` text NOT NULL, `catid` tinyint(5) NOT NULL default '1', `couponcode` text NOT NULL, PRIMARY KEY(`id));");
mysql_query("CREATE TABLE `".$_SESSION['prefix']."_products` ( `id` int(10) unsigned NOT NULL auto_increment, `name` text NOT NULL, `description` text NOT NULL, `keywords` text NOT NULL, `categoryid` text NOT NULL, `price` decimal(3,2) NOT NULL, PRIMARY KEY (`id`));");
mysql_query("CREATE TABLE `".$_SESSION['prefix']."_storecat` ( `id` int(10) unsigned NOT NULL auto_increment, `name` text NOT NULL, `description` text NOT NULL, `keywords` text NOT NULL, `parentid` tinyint(4) NOT NULL default '0', PRIMARY KEY (`id`) );");
mysql_query("INSERT INTO `".$_SESSION['prefix']."storecat` (1, 'products', '', '', 0);");
mysql_query("CREATE TABLE `".$_SESSION['prefix']."_comments` ( `id` int(10) unsigned NOT NULL auto_increment, `user` varchar(30) NOT NULL default '', `comment` text NOT NULL, `link_id` varchar(10) NOT NULL default '', PRIMARY KEY (`id`) );");
mysql_query("CREATE TABLE `".$_SESSION['prefix']."_links` ( `id` int(11) NOT NULL auto_increment, `name` text NOT NULL, `url` text NOT NULL, `description` text NOT NULL, `sitewide` varchar(10) NOT NULL default '', `published` char(1) NOT NULL default '', PRIMARY KEY (`id`) );");
mysql_query("CREATE TABLE `".$_SESSION['prefix']."_media` ( `id` int(10) unsigned NOT NULL auto_increment, `name` text NOT NULL, `description` text NOT NULL, `keywords` text NOT NULL, `url` text NOT NULL, `custom` text NOT NULL, `catergory_id` varchar(10) NOT NULL default '', `hits` int(11) NOT NULL default '0', `mpaa_rating` varchar(5) NOT NULL default '', `published` char(1) NOT NULL default '0', `user_submit` varchar(10) NOT NULL default '0', `width` varchar(4) NOT NULL default '', `height` varchar(4) NOT NULL default '', `image` text NOT NULL, `type` char(3) NOT NULL default '1', `import` char(1) NOT NULL default '0', `remote_image` char(1) NOT NULL default '0', `remote_media` char(1) NOT NULL default '0', `thedate` varchar(50) NOT NULL default '', `uploader` varchar(100) NOT NULL default '', `featured` char(1) NOT NULL default '0', `reported` CHAR( 1 ) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) );");
mysql_query("CREATE TABLE `".$_SESSION['prefix']."_pages` ( `id` int(10) unsigned NOT NULL auto_increment, `name` text NOT NULL, `page` text NOT NULL, `home` char(1) NOT NULL default '0', PRIMARY KEY (`id`) );");
mysql_query("INSERT INTO `".$_SESSION['prefix']."_pages` VALUES (1, 'Index Page', 'This is your home page. Edit this page as you please. Download a copy of <a href=http://thecollard.com>TheCollard</a> for yourself.', '1')");
mysql_query("CREATE TABLE `".$_SESSION['prefix']."_users` ( `id` int(10) unsigned NOT NULL auto_increment, `username` varchar(200) NOT NULL default '', `password` varchar(50) NOT NULL default '', `email` varchar(30) NOT NULL default '', `activate` char(1) NOT NULL default '0', `first_name` text NOT NULL , `last_name` text NOT NULL, `address` text NOT NULL, `phone` text NOT NULL, `city` varchar(75) NOT NULL default '', `state` varchar(200) NOT NULL default '', `admin` char(2) NOT NULL default '', `zip` int(11) NOT NULL default '0', `website` text NOT NULL, PRIMARY KEY (`id`) );");
mysql_query("INSERT INTO `".$_SESSION['prefix']."_users` VALUES (1, '', '', '', '1', '', '', '', '', '', '', '1', 0, '0')");
mysql_query("CREATE TABLE `".$_SESSION['prefix']."_orders` ( `id` int(12) unsigned NOT NULL auto_increment, `user` text NOT NULL, `email` text NOT NULL, `city` text NOT NULL, `state` text NOT NULL, `zip` text NOT NULL, `address` text NOT NULL, `products` text NOT NULL, PRIMARY KEY (`id`));");
mysql_query("CREATE TABLE `".$_SESSION['prefix']."_settings` ( `site_name` text NOT NULL, `site_url` text NOT NULL, `template_url` text NOT NULL, `max_results` text NOT NULL, `image_height` text NOT NULL, `image_width` text NOT NULL, `seo_on` char(1) NOT NULL default '', `email_on` char(2) NOT NULL default '', `allowsubmissions` tinyint(4) NOT NULL default '0' );");
mysql_query("INSERT INTO `".$_SESSION['prefix']."_settings` VALUES ('', '', '/template', '22', '85', '95', '1', '1', 1);");
mysql_query("CREATE TABLE `".$_SESSION['prefix']."_sitespecs` (`homepage` text NOT NULL, `paypal_id` text NOT NULL, `confirm` text NOT NULL, `cancel` text NOT NULL);");
mysql_query("INSERT INTO `".$_SESSION['prefix']."_sitespecs` VALUES('This is your homepage text','paypal@address.com','Your order confirmation page','Order cancellation page');");
$myFile = "../inc/config.php";
$fh = fopen($myFile, 'w') or die("Error creating config.php");
fwrite($fh, '<'.chr(63).'php
$server = \''.$_SESSION['host'].'\';
$username = \''.$_SESSION['dbname'] .'\';
$password = \''.$_SESSION['dbpass'] .'\'; // MySql Password
$database = \''.$_SESSION['dbtable'].'\'; // MySql Database
$host = $server;
$user = $username;
$pass = $password;
$name = $database;
$db = &new MySQL($host,$user,$pass,$name);
$con = mysql_connect("$server","$username","$password");
if (!$con) { die(\'Could not connect: \' . mysql_error()); }
mysql_select_db("$database", $con);
$SQL_Ext = \''.$_SESSION['prefix'].'\';
$sql = mysql_query("SELECT * FROM ".$SQL_Ext."_settings");
$row = mysql_fetch_array($sql);
$seotag = \''.$_SESSION['seo'].'\';
$shoptag = \''.$_SESSION['cart'].'\';
$site_description = \''.$_SESSION['desc'].'\';
$site_keywords = \''.$_SESSION['key'].'\';
$site_name = $row[\'site_name\'];
$site_url = $row[\'site_url\'];
$seo_on = $row[\'seo_on\'];
$template_url = $row[\'template_url\'];
$max_results = $row[\'max_results\'];
$image_height = $row[\'image_height\'];
$image_width = $row[\'image_width\'];
$email_on = $row[\'email_on\'];
$allowsubmissions = $row[\'allowsubmissions\'];
'.chr(63).'>');
fclose($fh);
$myFile1 = "../.htaccess";
$fh1 = fopen($myFile1, 'w') or die("Error creating config.php");
fwrite($fh, 'Options -Indexes
RewriteEngine on
RewriteRule ^'.$_SESSION['seo'].'/([0-9]+)-([a-zA-Z0-9?-]+) index.php?task=view&id=$1&name=$2 [L]
RewriteRule ^'.$_SESSION['cart'].'/([0-9]+)-([a-zA-Z0-9?-]+) index.php?task=view&id=$1&name=$2 [L]
RewriteRule ^([0-9]+)-([a-zA-Z0-9?-]+) index.php?task=articles&id=$1&name=$2 [L]
RewriteRule ^categories/([0-9]+).html$ index.php?task=viewcat&cat_id=$1&name=$2 [L]
RewriteRule ^categories/([0-9]+)?-p([0-9]+).html$ index.php?task=viewartcat&cat_id=$1&name=$2&page=$3 [L]
RewriteRule ^cat/([0-9]+)-([a-zA-Z0-9?-]+) index.php?task=viewcat&cat_id=$1&name=$2 [L]
RewriteRule ^cat/([0-9]+)-([a-zA-Z0-9?-]+)&page=([0-9]+) index.php?task=viewcat&cat_id=$1&name=$2&page=$3 [L]
RewriteRule ^cat/([0-9]+)-([a-zA-Z0-9?-]+)&page=([0-9]+) index.php?task=viewcat&cat_id=$1&page=$2 [L]
RewriteRule ^profile/([0-9]+)?/([a-zA-Z?-]+) index.php?task=profile&id=$1&name=$2 [L]
RewriteRule ^([0-9]+) index.php?task=view_page&id=$1 [L]
RewriteRule ^task/contact.html index.php?task=contact [L]
RewriteRule ^task/register.html index.php?task=register [L]
RewriteRule ^task/lost-password index.php?task=lost_pass [L]
RewriteRule ^task/links.html index.php?task=links [L]
RewriteRule ^task/members.html index.php?task=member_list [L]
RewriteRule ^task/email_sent.html index.php?task=sendemail [L]
RewriteRule ^search.html index.php?task=search [L]
RewriteRule ^store.html index.php?task=store [L]
RewriteRule ^shopping-cart.html index.php?task=cart [L]
RewriteRule ^update-cart.html index.php?task=update [L]
RewriteRule ^delete/([0-9]+)-([a-zA-Z0-9?-]+) index.php?task=delete&id=$1 [L]
RewriteRule ^order/([0-9]+)-([a-zA-Z0-9?-]+) index.php?task=add&id=$1&name=$2 [L]
RewriteRule ^feed rss.php [L]
RewriteBase /';
?>
<table cellpadding="0" border="0" width="260">
<tr>
<td colspan="2" align="center" valign="center">
<br />
Step 2: Config.php Created and mysql connection information saved.. Please press next page to proceed to the next step of the install.
<br />
<br />
</td>
</tr>
<tr><td>Goto the Next Page</td></tr>
<tr><td align="right"><a href="index.php?page=3">Next Step</a></td></tr>
</table>
<?
}
if ($_REQUEST['page'] == 3)
{
$con = @mysql_connect ($_SESSION['host'],$_SESSION['dbname'], $_SESSION['dbpass']) or die ("<br>Can not make the connection to the database.<br><br> <a href='index.php'>Click here to enter connection details.</a><br><br>");
$db = @mysql_select_db ($_SESSION['dbtable'],$con) or die ("<br>Can not connect to database. <br><br> <a href='index.php'>Click here to enter connection details.</a><br><br>");
?>
<form action="index.php?page=4" method="post" style="display:inline;">
<table cellpadding="0" border="0" width="260">
<tr>
<td colspan="2" align="center" valign="center">
<br />
Step 3: Enter your sites configuration.
<br />
<br />
</td>
</tr>
<tr>
<td>Site Name</td>
<td><input type="text" name="site_name" size="20"></td>
</tr>
<tr>
<?php $website = $_SERVER['HTTP_HOST']; ?>
<td>Site Url</td>
<td><input type="text" name="site_url" size="20" value="http://<?=$website?>"></td>
</tr>
<tr>
<td>SEO On</td>
<td><input type="checkbox" name="seo_on" checked></td>
</tr>
<tr>
<td><br></td>
<td></td>
</tr>
<tr>
<td colspan="2"><b>Administration Setup</b></td>
</tr>
<tr>
<td>Admin Name</td>
<td><input type="text" name="admin_name" size="20"></td>
</tr>
<tr>
<td>Admin Password</td>
<td><input type="password" name="admin_pass" size="20"></td>
</tr>
<tr>
<tr>
<td>Admin Email</td>
<td><input type="text" name="email" size="20"></td>
</tr>
<tr>
<td><br></td>
<td></td>
</tr>
<tr><td colspan="2" align="right"><input type="submit" name="submit" value="Submit"><br /><br /></td></tr>
</table>
</form>
<?
}
if ($_REQUEST['page'] == 4)
{
$con = @mysql_connect ($_SESSION['host'],$_SESSION['dbname'], $_SESSION['dbpass']) or die ("<br>Can not make the connection to the database.<br><br> <a href='index.php'>Click here to enter connection details.</a><br><br>");
$db = @mysql_select_db ($_SESSION['dbtable'],$con) or die ("<br>Can not connect to database. <br><br> <a href='index.php'>Click here to enter connection details.</a><br><br>");
if($_REQUEST['seo_on'] == 'on') { $seoon = '1'; }
else { $seoon = '0'; }
$adminpass = md5($_REQUEST['admin_pass']);
$_SESSION['name'] = $_REQUEST['admin_name'];
$_SESSION['pass'] = $_REQUEST['admin_pass'];
$_SESSION['site_url'] = $_REQUEST['site_url'];
$_SESSION['email'] =$_REQUEST['email'];
mysql_query("UPDATE `".$_SESSION['prefix']."_settings` SET `site_name` = '".$_REQUEST['site_name']."', `site_url` = '".$_REQUEST['site_url']."', `seo_on` = '".$seoon."'");
mysql_query("UPDATE `".$_SESSION['prefix']."_users` SET `username` = '".$_REQUEST['admin_name']."', `password` = '".$adminpass."', `email` = '".$_REQUEST['email']."' WHERE `id` = '1'");
?>
<table cellpadding="0" border="0" width="260">
<tr>
<td align="center" valign="center">
<br />
Script Setup: Setup Finished
<br />
<br />
</td>
</tr>
<tr><td>The content management and cart site set-up has finished.
You can now log into your admin panel.
<b> Do not forget to erase this folder</b>
<br><br> Name: <?php echo $_SESSION['name']; ?>
<br> Pass: <?php echo $_SESSION['pass']; ?><br>
<br><a href="<?=$_SESSION['site_url'];?>/admin/index.php">Click here</a><br><br></td></tr>
</table>
<?
}
?>
</div><img src="footer.png"></center>
</body>
</html>
Now that this page is completed, we will want to save the index.php file again into the install folder. Also, we need to get the graphics for the page.
Here are the images. Right click and save to the install folder.
Top of page

Bottom of page

Background

Download the entire install.zip file
