Another addition to the HCS Forum package by Captain Ron at 1:19 AM EDT on August 12, 2011
As you all know, even though it's actually easy to implement the HCS Forum on any website that supports PHP & MySQL, most people who decide to use computers are either n00bs, or don't know how to research old forum topics to dig up scattered source code snippets.

So, I created an automated installation script for the forum! Here's the full source for the installation script:

<?php
$File1 = "dblogin.php";
$File2 = "dblogin_write.php";
$setup_dump = "hcsforumsetup.sql";
if (file_exists($File1) && file_exists($File2))
{
print "The forum is already installed.";
}
else
{
$Handle1 = fopen($File1, 'w');
$Handle2 = fopen($File2, 'w');
$Handle3 = fopen($setup_dump, 'w');
$server = ""; // IP of MySQL Server (if it's the same as the HTTP/FTP server, write "localhost").
$username1 = ""; // Full-privilege MySQL account username.
$username2 = ""; // Low-privilege MySQL account username. If there's only one MySQL account,
$password1 = ""; // Full-privilege MySQL account password. leave username2 & password2 blank.
$password2 = ""; // Low-privilege MySQL account password.
$database = ""; // MySQL database name.
if (!($username2))
{
fwrite($Handle1, "<?php\r\nfunction dblogin() {\r\n\$dbh = mysqli_connect(\"$server\", \"$username1\", \"$password1\", \"$database\") or
die(mysqli_error(\$dbh));\r\nreturn \$dbh;\r\n}\r\n?>");
fwrite($Handle2, "<?php\r\nfunction dblogin_write() {\r\n\$dbh_write = mysqli_connect(\"$server\", \"$username1\", \"$password1\", \"$database\") or
die(mysqli_error(\$dbh_write));\r\nreturn \$dbh_write;\r\n}\r\n?>");
}
else
{
fwrite($Handle1, "<?php\r\nfunction dblogin() {\r\n\$dbh = mysqli_connect(\"$server\", \"$username1\", \"$password1\", \"$database\") or
die(mysqli_error(\$dbh));\r\nreturn \$dbh;\r\n}\r\n?>");
fwrite($Handle2, "<?php\r\nfunction dblogin_write() {\r\n\$dbh_write = mysqli_connect(\"$server\", \"$username2\", \"$password2\", \"$database\") or
die(mysqli_error(\$dbh_write));\r\nreturn \$dbh_write;\r\n}\r\n?>");
}
fclose($Handle1);
fclose($Handle2);
fwrite($Handle3, "CREATE TABLE IF NOT EXISTS `board` (\r\n`idx` int(11) NOT NULL auto_increment,\r\n`postedtime` datetime NOT NULL default
'0000-00-00 00:00:00',\r\n`lasttime` datetime NOT NULL default '0000-00-00 00:00:00',\r\n`author` int(11) NOT NULL default '0',\r\n`replyto` int(11)
NOT NULL default '0',\r\n`subject` varchar(255) collate utf8_unicode_ci default NULL,\r\n`message` text collate utf8_unicode_ci,\r\n`ip` varchar(15)
collate utf8_unicode_ci default NULL,\r\nKEY `idx` (`idx`),\r\nKEY `replyto` (`replyto`),\r\nKEY `author` (`author`)\r\n) ENGINE=MyISAMDEFAULT
CHARSET=utf8 COLLATE=utf8_unicode_ci ;\r\n\r\nCREATE TABLE IF NOT EXISTS `users` (\r\n`idx` int(11) NOT NULL auto_increment,\r\n`joined` datetime
NOT NULL default '0000-00-00 00:00:00',\r\n`uname` varchar(31) collate utf8_unicode_ci NOT NULL default '',\r\n`pass` varchar(31) collate
utf8_unicode_ci NOT NULL default '',\r\n`lastlogin` datetime NOT NULL default '0000-00-00 00:00:00',\r\n`prevlogin` datetime NOT NULL default
'0000-00-00 00:00:00',\r\n`logintoken` varchar(32) collate utf8_unicode_ci NOT NULL default '',\r\nKEY `idx` (`idx`)\r\n) ENGINE=MyISAMDEFAULT
CHARSET=utf8 COLLATE=utf8_unicode_ci ;\r\n");
fclose($Handle3);
exec("mysql -u $username2 -p $password2 $database < hcsforumsetup.sql");
while(is_file($setup_dump) == TRUE)
{
chmod($setup_dump, 0666);
unlink($setup_dump);
}
print "The forum has been successfully installed.";
}
?>


All you need to do is input your database's name, MySQL server URI & MySQL account credentials for both full- & low-privileged users. The script will automatically generate the dblogin.php & dblogin_write.php scripts to access the database, as well as automatically generate & the database's schema.

Copy the above code & save it as install.php; edit the code as required. Save hcs' forum source(either the copy at the bottom of this page, or the index.php file from my custom package) & upload both files onto your server. Lastly, use a web browser to visit install.php's URL & presto; the database will be prepared & the forum will be ready to go.

If anyone decides to use this, please let me know of any bugs.

hcs; I hope you like this addition to your forum's source code. ;)

edited 10:07 PM EDT August 12, 2011
by Captain Ron at 9:46 PM EDT on August 14, 2011
One thing I forgot to mention; due to the mysql console command embedded in the code, this implies that you need proper shell permissions (i.e.: you need to also have SSH access to your website). This script only makes the task of importing the schema easier (if you have shell permissions).


Go to Page 0

Search this thread

Show all threads

Reply to this thread:

User Name Tags:

bold: [b]bold[/b]
italics: [i]italics[/i]
emphasis: [em]emphasis[/em]
underline: [u]underline[/u]
small: [small]small[/small]
Link: [url=http://www.google.com]Link[/url]

[img=https://www.hcs64.com/images/mm1.png]
Password
Subject
Message

HCS Forum Index
Halley's Comet Software
forum source