Usersystem installation


This script will show you how to create an installer for your website. Good for if you are creating a CMS Type system and wish to distribute it.
Notice: Read The Comments!

Requirements

  • User System Part 1


Please call this file install.php x]

PHP Code
  1. <?php
  2. /**
  3.  * This script was made by MOD-Shadow of rmb-scripting.com
  4.  * DO NOT REMOVE
  5.  */
  6. session_start(); //allow sessions.
  7. $step = (int)$_GET['step']; //current step for INT Only.
  8. if (!$step || empty($step) || $step == '1') { //check if $step is nul or the step is 1
  9. print "<p>
  10. Welcome to the User System Installation script tutorial x] To begin, Click the link below.
  11. <a href=\"install.php?step=2\">Database Information</a>
  12. </p>"; //simple welcome mesage with link to step 2
  13. exit(); //go no further
  14. } //end welcome
  15. if ($step == '2') { //database setup x]
  16. if (!$_POST['db_setup']) { //form wasn't submitted
  17. print "<h2>Database Setup</h2>
  18. <form method=\"post\" action=\"$_SERVER[PHP_SELF]?step=2\">
  19. <p>
  20. <label>DB Host</label>
  21. <input type=\"text\" name=\"host\" value=\"localhost\" size=\"15\" />
  22. <label>DB Username</label>
  23. <input type=\"text\" name=\"user\" value=\"root\" size=\"15\" />
  24. <label>DB Password</label>
  25. <input type=\"password\" name=\"pass\" value=\"\" size=\"15\" />
  26. <label>DB Name</label>
  27. <input type=\"text\" name=\"name\" value=\"\" size=\"15\" />
  28. <input type=\"submit\" name=\"db_setup\" value=\"Submit Details\" />
  29. </p>
  30. </form>"; //echo the form x]
  31. exit(); //go no further
  32. } else { //it was x]
  33. $host = $_POST['host']; //the DB Host
  34. $user = $_POST['user']; //DB User
  35. $pass = $_POST['pass']; //DB Pass
  36. $name = $_POST['name']; //DB Name
  37. $errors = array(); //array for errors x]
  38. if (empty($host)) { //if host is empty
  39. $errors[] = "You Must Enter A Host."; //our error
  40. } //end host check
  41. if (empty($user)) { //user check
  42. $errors[] = "You Must Enter A Username"; //:O Invalid username!
  43. } //end user check
  44. if (empty($pass)) { //check password.
  45. $errors[] = "You Must Enter a Password"; //the error
  46. } //end pass check
  47. if (empty($name)) { //database name check
  48. $errors[] = "You Must Enter a Database Name"; //You Fail. O_o
  49. } //end db name check
  50. if (count($errors) > 0) { //if theres more then 0 errors
  51. print "<h2>Errors Found!</h2>
  52. <p>"; //error header
  53. foreach ($errors as $err) { //foreach error
  54. print $err . ''; //print them out
  55. } //end loop
  56. print "</p>"; //end paragraph x]
  57. exit(); //go no further
  58. } else { //YAY No Errors
  59. $connect = @mysql_connect($host, $user, $pass); //test our information
  60. if (!$connect) { //didnt work :(
  61. $con_test = "<span style=\"color:red\">False</span>"; //our connect status
  62. $cerror = true; //return a true for error
  63. } else { //it worked!!!
  64. $con_test = "<span style=\"color:green\">Green</span>"; //connect stats
  65. $cerror = false; //returns false for error.
  66. } //end error check
  67. $dbtest = @mysql_select_db($name, $connect);
  68. if (!$dbtest) { //didnt work :(
  69. $db_test = "<span style=\"color:red\">False</span>"; //our db test status
  70. $derror = true; //return a true for error
  71. } else { //it worked!!!
  72. $db_test = "<span style=\"color:green\">Green</span>"; //db test stats
  73. $derror = false; //returns false for error.
  74. } //end error check
  75. print "<table>
  76. <tr>
  77. <td width=\"150\">
  78. <strong>Connection Stats</strong>
  79. </td>
  80. <td width=\"150\">
  81. $con_stats
  82. </td>
  83. </tr>
  84. <tr>
  85. <td width=\"150\">
  86. <strong>DB Stats</strong>
  87. </td>
  88. <td width=\"150\">
  89. $db_stats
  90. </td>
  91. </tr>
  92. </table>"; //our stats in a nice table.
  93. if ($cerror) { //if connect error
  94. print "<h2>Connection Error</h2>
  95. <p>
  96. Connection failed. Please go back and check your details.
  97. <a href=\"javascript:history.go(-1);\">Go Back</a>
  98. </p>"; //lets tell them
  99. exit(); //go no further
  100. } //end connect error
  101. if ($derror) { //dbtest error obviously going to be true if connect is true.
  102. print "<h2>Database Error</h2>
  103. <p>
  104. Could not connect to database. Attempting to create.....
  105. <a href=\"javascript:history.go(-1);\">Go Back</a>
  106. </p>"; //tell them they made a boo boo
  107. $create_db = @mysql_query("CREATE DATABASE `$name`");
  108. if (!$create_db) {
  109. print "<p>
  110. Database Creation Failed.
  111. </p>";
  112. }
  113. exit(); //go no further
  114. } //end db test error.
  115. if (!$cerror && !$derror) { //No Error found!!!!!!!!!!
  116. $conf_handle = fopen('config.php', 'w+');
  117. $data = "<?php
  118. session_start(); //allows session
  119.  
  120. \$connect = @mysql_connect($host,$user,$pass);
  121. \$db = @mysql_select_db(\$db,\$connect);
  122.  
  123. \$logged = @mysql_query(\"SELECT * FROM `members` WHERE `id` = '\$_SESSION[id]' AND `password` = '\$_SESSION[password]'\");
  124. \$logged = @mysql_fetch_array(\$logged);
  125.  
  126. //some server details, don't edit!
  127. \$host = \$_SERVER['HTTP_HOST'];
  128. \$self = \$_SERVER['PHP_SELF'];
  129.  
  130. //change this to your site name
  131. \$sitename = \"My Site\";
  132.  
  133. //Send emails or not (email activation). 1 = true, 0 = false
  134. \$semail = \"1\";
  135. ?>";
  136. $write = @fwrite($conf_handle, $data);
  137. if ($write) {
  138. print "<h2>Success</h2>
  139. <p>
  140. Config File Created! To continue the installation please click the link below.
  141. <span style=\"color:red\">NOTICE: PLEASE CHMOD CONFIG FILE TO 0644</span>
  142. <a href=\"install.php?step=3\">Setup Tables</a>
  143. </p>";
  144. exit(); //go no further.
  145. } else {
  146. print "<h2>Error</h2>
  147. <p>
  148. Config File Creation Failed. Please check and make sure your CHMOD Perms are 0777 before performing this step again.
  149. <a href=\"javascript:history.go(-1);\">Go Back</a>
  150. </p>";
  151. exit(); //go no further
  152. } //end write check
  153. } //end no error check
  154. } //end error check
  155. } //end form submit check
  156. } //end step check
  157. if ($step == '3') {
  158. require("config.php"); //require newly found config.php x]
  159. $create_members = mysql_query("CREATE TABLE `members` (
  160. `id` int(11) NOT NULL auto_increment,
  161. `username` varchar(30) NOT NULL default '',
  162. `password` varchar(255) NOT NULL default '',
  163. `email` varchar(55) NOT NULL default '',
  164. `location` varchar(40) NOT NULL default 'N/A',
  165. `userlevel` int(3) NOT NULL default '1',
  166. `age` int(3) NOT NULL,
  167. `sex` varchar(40) NOT NULL default 'N/A',
  168. PRIMARY KEY (`id`)
  169. ) TYPE=MyISAM;"); //create our members table...or...attempt to.....
  170.  
  171. $create_verification = mysql_query("CREATE TABLE `verification` (
  172. `id` int(11) NOT NULL auto_increment,
  173. `username` varchar(30) NOT NULL default '',
  174. `code` varchar(255) NOT NULL default '',
  175. PRIMARY KEY (`id`)
  176. ) TYPE = MYISAM;"); //attempt to create verification table
  177. if(!$create_members){ //members check
  178. $mem_stats = "<span style=\"color :red;\">False</span>"; //our stats
  179. $merror = true; //OH NO
  180. }else{ //no error
  181. $mem_stats = "<span style=\"color:green;\">True</span>"; //GREEN!!!
  182. $merror = false; //no error
  183. } //end check
  184. if(!$create_verification){ //error found
  185. $pms_stats = "<span style=\"color:red;\">False</span>"; //red false
  186. $verror = true; //true for error
  187. }else{ //or not?
  188. $pms_stats = "<span style=\"color:green;\">True</span>"; //its good to go
  189. $verror = false; //no error
  190. }
  191. print "<table width=\"200\">
  192. <tr>
  193. <td width=\"150\">
  194. <strong>Members</strong>
  195. </td>
  196. <td width=\"50\">
  197. $mem_stats
  198. </td>
  199. </tr>
  200. <tr>
  201. <td width=\"150\">
  202. <strong>Verification</strong>
  203. </td>
  204. <td width=\"50\">
  205. $ver_stats
  206. </td>
  207. </tr>
  208. </table>"; //nice table x]
  209. if($merror){ //error in members
  210. print "<p>
  211. members Table Creation Failed!
  212. Please Use <a href=\"https://$host:2082/3rdparty/phpMyAdmin/index.php\">phpMyAdmin</a> To Create the table.
  213. </p>"; //tell them and give link to Cpanel.
  214. exit(); //go no further
  215. } //end members error
  216. if($verror){ //verification error
  217. print "<p>
  218. verification Table Creation Failed!
  219. Please Use <a href=\"https://$host:2082/3rdparty/phpMyAdmin/index.php\">phpMyAdmin</a> To Create the table.
  220. </p>"; //give link to cpanel and such
  221. exit(); //go no further
  222. } //end verification error
  223. if(!$merror && !$verror){ //no errors
  224. print "<h2>Success</h2>
  225. <p>
  226. Tables Created!
  227. <a href=\"install.php?step=4\">Admin Setup</a>
  228. </p>"; //success!!!!
  229. exit(); //go no further
  230. }
  231. } //end step check
  232. if ($step == '4') { //step 4 YAYZZ
  233. require("config.php"); //get config
  234. if(!$_POST['admin_setup']){ //form not submitted
  235. print "<form method=\"post\" action=\"$_SERVER[PHP_SELF]?step=4\">
  236. <p>
  237. <label>Admin Username</label>
  238. <input type=\"text\" name=\"user\" size=\"15\" />
  239. <label>Admin Password</label>
  240. <input type=\"password=\" name=\"pass\" size=\"15\" />
  241. <label>Admin Email</label>
  242. <input type=\"text\" name=\"mail\" size=\"15\" />
  243. <input type=\"submit\" name=\"admin_setup\" value=\"Save Admin\" />
  244. </p>
  245. </form>"; //submit form.
  246. }else{ //form submitted
  247. $username = $_POST['user']; //our username
  248. $password = sha1(md5(md5(sha1(md5(sha1(sha1(md5($_POST['pass'])))))))); //secure pass
  249. $email = $_POST['mail']; //the admin email
  250. if(empty($username) || empty($password) || empty($email)){ //check for empty field
  251. print "<h2>Error</h2>
  252. <p>
  253. You Must Fill Out All Fields!
  254. </p>"; //give error
  255. exit(); //go no further
  256. }else{ //no error
  257. $insert = mysql_query("INSERT INTO `members` (`username`,`password`,`email`,`userlevel`) VALUES ('$username','$password','$email','6');"); //insert admin data.
  258. if($insert){ //check if error
  259. print "<h2>Success</h2>
  260. <p>
  261. Admin User Setup!
  262. <a href=\"install.php?step=5\">Finish</a>
  263. </p>"; //no error found
  264. exit(); //go no further
  265. }else{ //insert failed.
  266. print "<h2>Error</h2>
  267. <p>
  268. Error Returned: ".mysql_error()."
  269. </p>"; //you have an error!!!
  270. exit(); //go no further.
  271. } //no error.
  272. }//end error check
  273. } //end form check
  274. } //end step check
  275. if ($step == '5') { //FINAL STEP WOOHOO
  276. print "<h2>Complete!</h2>
  277. <p>
  278. Setup Complete! Please delete this file and CHMOD config.php back to 0644 so hackers can not attack your website.
  279. </p>"; //give finished message
  280. chmod("config.php", '0644'); //chmod the config to 0644 if not done already.
  281. unlink("install.php"); //delete install file.
  282. } //end step check x]
  283. ?>
ShadowMage's Avatar
Author:
Views:
4,742
Rating:
Posted on Sunday 20th July 2008 at 06:07 PM
Paul
Paul's Avatar
i get the below error

Parse error: syntax error, unexpected ',', expecting ')' in /home/sites/sthelensclubberz.co.uk/public_html/config.php on line 5


any help would be brillant
Posted on Sunday 20th July 2008 at 05:28 PM
Paul
Paul's Avatar
were it says

$errors[] = "You Must Enter A Host."; //our error
} //end host check
if (empty($user)) { //user check
$errors[] = "You Must Enter A Username"; //:O Invalid username!
} //end user check
if (empty($pass)) { //check password.
$errors[] = "You Must Enter a Password"; //the error
} //end pass check
if (empty($name)) { //database name check
$errors[] = "You Must Enter a Database Name"; //You Fail. O_o
} //end db name check


i put my host in along with username and password and comes up with

Errors Found!
FractixPaulbigandbanginweb176-website

any help would be great
Posted on Thursday 19th June 2008 at 11:41 PM
jambomb
jambomb's Avatar
thats just lazyness lol then u would prob have to copy the code from the download lol
Posted on Wednesday 18th June 2008 at 09:00 PM
ilyas-shezad
ilyas-shezad's Avatar
It might be a simple installer but its a long long piece of script.
You should put up on the downloads so that people can download insteada copying n pasting :P
Posted on Thursday 15th May 2008 at 07:17 PM
peza
peza's Avatar
Im getting the error Parse error: syntax error, unexpected ',', expecting ')' in /home/aftermat/public_html/v2/system/config.php on line 5
Posted on Thursday 15th May 2008 at 07:17 PM
peza
peza's Avatar
Im getting the error Parse error: syntax error, unexpected ',', expecting ')' in /home/aftermat/public_html/v2/system/config.php on line 5
Posted on Thursday 8th May 2008 at 09:57 PM
DanielXP
DanielXP's Avatar
I love installers!!!!

Best part of like a few script. thats why plus news one is better than the script itself :p
Posted on Wednesday 7th May 2008 at 02:02 AM
ShadowMage
ShadowMage's Avatar
Ive updated this code :3 so if you have the $_SESSION[currentstep] type stuff update to the new code and it should execute x]
Posted on Wednesday 7th May 2008 at 01:33 AM
DjMilez
DjMilez's Avatar
It tells me that it's redirecting the request in a way that will never complete.
Posted on Wednesday 30th April 2008 at 09:14 PM
UrbanTwitch
UrbanTwitch's Avatar
The requested URL: /install/install.php?step=2 is not available.

:(