big-dog1965 Posted February 19, 2009 Share Posted February 19, 2009 Here’s a big one guys, I have a setup.php file that creates a config file that I would like to incorporate another config file into so I only have one config file. setup.php is the file that you execute to setup the database connection it references language.php then the system.php is used for another part of my app. Well someone take a look and see what needs to be done or if its even possible. I got this stuff from a couple of differant scripts and modified to do what I want, but I would like to combine and dont have a clue. <?php setup.php THIS IS THE ECECUTABLE THAT SETS UP THE DATABASE AND CREATS THE CONFIG.PHP FILE if(is_array($_POST)){ $HTTP_POST_VARS=$_POST; } if(is_array($_GET)){ $HTTP_GET_VARS=$_GET; } include(dirname(__FILE__)."/language.php"); $divFormat="<div style=\"text-align: center; font-weight: bold; font-family: verdana,arial; font-size: 15px;\">"; $backHome="$divFormat<a href=\"./\">".$Translation["goto start page"]."</a></div>"; // check this file's MD5 to make sure it wasn't called before $prevMD5=@implode('', @file("./setup.md5")); $thisMD5=md5(@implode('', @file("./setup.php"))); if($thisMD5==$prevMD5){ echo "$divFormat ".$Translation["setup performed"]." ".date("r", filemtime("./setup.md5")).".<br><br></div>"; echo "$divFormat<div style=\"font-size: 10px;\">".$Translation["delete md5"]."</div></div><br><br>"; echo $backHome; exit; } // connect to the database $dbServer=$HTTP_POST_VARS['dbServer']; $dbUsername=$HTTP_POST_VARS['dbUsername']; $dbPassword=$HTTP_POST_VARS['dbPassword']; $dbDatabase=$HTTP_POST_VARS['dbDatabase']; $noDB=0; if(!@mysql_connect($dbServer, $dbUsername, $dbPassword)){ $noDB=1; }elseif(!@mysql_select_db($dbDatabase)){ if(!@mysql_query("create database `$dbDatabase`")){ $noDB=2; }else{ if(!@mysql_select_db($dbDatabase)){ $noDB=2; } } } // if no connection established, ask for connection data if($noDB){ if($dbServer!=''){ echo $divFormat."<div style=\"color: red;\">".($noDB==1 ? $Translation["no db connection"] : str_replace("<DBName>", $dbDatabase, $Translation["no db name"]))."</div>"."</div>"; } ?> <form method="post" action="setup.php"> <?php echo $divFormat; ?> <?php echo $Translation["provide connection data"]; ?> <br><br><center> <table bgcolor="#BFD5FF" style="border: solid silver 1px;" width="400"> <tr> <td align="right"><?php echo $divFormat; ?><?php echo $Translation["mysql server"]; ?></div></td> <td><input type="text" name="dbServer" size="20"></td> </tr> <tr> <td align="right"><?php echo $divFormat; ?><?php echo $Translation["mysql username"]; ?></div></td> <td><input type="text" name="dbUsername" size="10"></td> </tr> <tr> <td align="right"><?php echo $divFormat; ?><?php echo $Translation["mysql password"]; ?></div></td> <td><input type="password" name="dbPassword" size="10"></td> </tr> <tr> <td align="right"><?php echo $divFormat; ?><?php echo $Translation["mysql db"]; ?></div></td> <td><input type="text" name="dbDatabase" size="15"></td> </tr> <tr> <td align="left" colspan="2"><b> <font size="1" color="#FF0000">Before proceeding Did you</font></b></td> </tr> <tr> <td align="left" colspan="2"><b><font size="1">Change the email address in <u>setup.php</u> at or about line 116</font></b></td> </tr> <tr> <td align="left" colspan="2"><b><font size="1">Edit <u>system.php</u> with this same information to connect to database</font></b></td> </tr> <tr> <td align="left" colspan="2"><b><font size="1">Also change the information in the next block as indicated</font></b></td> </tr> <tr> <td align="right"></td> <td><input type="submit" value="<?php echo $Translation["connect"]; ?>"></td> </tr> </table> </center></div> </div> </form> <?php exit; }else{ // if connection is successful, save parameters into config.php if(!$fp=@fopen("./config.php", "w")){ echo $divFormat."<div style=\"color: red;\">".$Translation["couldnt save config"]."</div></div><br>"; echo $backHome; exit; }else{ fwrite($fp, "<?php\n"); fwrite($fp, "\t\$dbServer=\"$dbServer\";\n"); fwrite($fp, "\t\$dbUsername=\"$dbUsername\";\n"); fwrite($fp, "\t\$dbPassword=\"$dbPassword\";\n"); fwrite($fp, "\t\$dbDatabase=\"$dbDatabase\";\n"); fwrite($fp, "?>"); fclose($fp); } } // set up tables echo '<p>Creating table ClanApps'; if(!$result = mysql_query('CREATE TABLE IF NOT Exists ClanApps ( id INT(10) unsigned not null auto_increment , In_game_Name VARCHAR(20) , GSC_Login_Name VARCHAR(20) , Date_of_Birth VARCHAR(10) , Age VARCHAR(2) , State_Province VARCHAR(25) , Country VARCHAR(20) , Hear_About_TB VARCHAR(255) , Tactical_Realism VARCHAR(255) , Enjoyable_Gaming VARCHAR(255) , Join_Tactical_Brotherhood VARCHAR(255) , Former_CoD_Clan_1 VARCHAR(25) , Clan_1_Duration VARCHAR(25) , Former_CoD_Clan_2 VARCHAR(25) , Clan_2_Duration VARCHAR(25) , Former_CoD_Clan_3 VARCHAR(25) , Clan_3_Duration VARCHAR(25) , Active_Presence VARCHAR(3) , EMail VARCHAR(40) , IP_Address TEXT , Date_Submitted TEXT , Approved TEXT , primary key (id))')) { echo ' Error creating Table ' . mysql_error(); } echo '<p>Creating table login'; if(!$result = mysql_query('CREATE TABLE IF NOT Exists login ( userid int(35) NOT NULL auto_increment , user_name varchar(50) NOT NULL , user_pass varchar(255) NOT NULL , user_level varchar(50) NOT NULL , `date` varchar(20) default NULL , user_email varchar(50) NOT NULL , user_ip varchar(50) NOT NULL , PRIMARY KEY (userid) )')) { echo ' Error creating Table ' . mysql_error(); } echo '<p>Inserting admin data into table Login'; mysql_query("INSERT INTO login VALUES ('','admin','21232f297a57a5a743894a0e4a801fc3','4','02-19-2009','[email protected]','' )") or die(mysql_error()); echo "<p>Tables installed correctly"; echo "<p>Admin User Name admin Password admin"; // save MD5 if($fp=@fopen("./setup.md5", "w")){ fwrite($fp, $thisMD5); fclose($fp); } // go to index echo $backHome; // ------------------------------------------ function setupTable($tableName, $createSQL='', $arrAlter=''){ global $Translation; echo "<div style=\"padding: 5px; border-bottom:solid 1px silver; font-family: verdana, arial; font-size: 10px;\">"; if($res=@mysql_query("select count(1) from `$tableName`")){ if($row=@mysql_fetch_array($res)){ echo str_replace("<TableName>", $tableName, str_replace("<NumRecords>", $row[0],$Translation["table exists"])); if(is_array($arrAlter)){ echo '<br>'; foreach($arrAlter as $alter){ if($alter!=''){ echo "$alter ... "; if(!@mysql_query($alter)){ echo "<font color=red>".$Translation["failed"]."</font><br>"; echo "<font color=red>".$Translation["mysql said"]." ".mysql_error()."</font><br>"; }else{ echo "<font color=green>".$Translation["ok"]."</font><br>"; } } } }else{ echo $Translation["table uptodate"]; } }else{ echo str_replace("<TableName>", $tableName, $Translation["couldnt count"]); } }else{ echo str_replace("<TableName>", $tableName, $Translation["creating table"]); if(!@mysql_query($createSQL)){ echo "<font color=red>".$Translation["failed"]."</font><br>"; echo "<font color=red>".$Translation["mysql said"].mysql_error()."</font>"; }else{ echo "<font color=green>".$Translation["ok"]."</font>"; } } echo "</div>"; } ?> <?php language.php THIS IS REFERANCES FROM THE SETUP.PHP FILE // IMPORTANT: // ========== // When translating, only translate the strings that are // TO THE RIGHT OF the equal sign (=). // // Do NOT translate the strings between square brackets ([]) // // Also, leave the text between < and > untranslated. // datalist.php $Translation["powered by"] = "<a href=http://www.mysite/>Big-Dog</a> - Powered by"; $Translation["quick search"] = "Quick Search"; $Translation["records x to y of z"] = "Records <FirstRecord> to <LastRecord> of <RecordCount>"; $Translation["filters"] = "Filters"; $Translation["filter"] = "Filter"; $Translation["filtered field"] = "Filtered field"; $Translation["comparison operator"] = "Comparison Operator"; $Translation["comparison value"] = "Comparison Value"; $Translation["and"] = "And"; $Translation["or"] = "Or"; $Translation["equal to"] = "Equal to"; $Translation["not equal to"] = "Not equal to"; $Translation["greater than"] = "Greater than"; $Translation["greater than or equal to"] = "Greater than or equal to"; $Translation["less than"] = "Less than"; $Translation["less than or equal to"] = "Less than or equal to"; $Translation["like"] = "Like"; $Translation["not like"] = "Not like"; $Translation["apply filters"] = "Apply filters"; $Translation["save filters"] = "Save and apply filters"; $Translation["saved filters title"] = "HTML Code For The Applied Filters"; $Translation["saved filters instructions"] = "Copy the code below and paste it to an HTML file to save the filter you just defined so that you can return to it at any time in the future without having to redefine it. You can save this HTML code on your computer or on any server and access this prefiltered table view through it."; $Translation["hide code"] = "Hide this code"; $Translation["printer friendly view"] = "Printer-friendly view"; $Translation["save as csv"] = "Download as csv file (comma-separated values)"; $Translation["edit filters"] = "Edit filters"; $Translation["clear filters"] = "Clear filters"; $Translation['order by'] = 'Order by'; $Translation['go to page'] = 'Go to page:'; $Translation['none'] = 'None'; // _dml.php $Translation["are you sure?"] = "Are you sure you want to delete this record?"; $Translation["add new record"] = "Add new record"; $Translation["update record"] = "Update record"; $Translation["delete record"] = "Delete record"; $Translation["deselect record"] = "Deselect record"; $Translation["couldn't delete"] = "Couldn't delete record due to presence of <RelatedRecords> related record(s) in table '<TableName>'"; $Translation["pkfield empty"] = " field is a primary key field and cannot be empty."; $Translation["upload image"] = "Upload new file "; $Translation["select image"] = "Select an image "; $Translation["remove image"] = "Remove file"; $Translation["month names"] = "January,February,March,April,May,June,July,August,September,October,November,December"; $Translation["field not null"] = "You can't leave this field empty."; $Translation["*"] = "*"; // lib.php $Translation["select a table"] = "Go to table"; $Translation["homepage"] = "Homepage"; $Translation["error:"] = "Error:"; $Translation["sql error:"] = "SQL error:"; $Translation["query:"] = "Query:"; $Translation["< back"] = "< Back"; $Translation["if you haven't set up"] = "If you haven't set up the database yet, you can do so by clicking <a href='setup.php'>here</a>."; // setup.php $Translation["goto start page"] = "Back to start page"; $Translation["no db connection"] = "Couldn't establish a database connection."; $Translation["no db name"] = "Couldn't access the database named '<DBName>' on this server."; $Translation["provide connection data"] = "Please provide the following data to connect to the database:"; $Translation["mysql server"] = "MySQL server (host)"; $Translation["mysql username"] = "MySQL Username"; $Translation["mysql password"] = "MySQL password"; $Translation["mysql db"] = "Database name"; $Translation["connect"] = "Connect"; $Translation["couldnt save config"] = "Couldn't save connection data into 'config.php'.<br>Please make sure that the folder:<br>'".dirname(__FILE__)."'<br>is writable (chmod 775 or chmod 777)."; $Translation["setup performed"] = "Setup already performed on"; $Translation["delete md5"] = "If you want to force setup to run again, you should first delete the file 'setup.md5' from this folder."; $Translation["table exists"] = "Table <b><TableName></b> exists, containing <NumRecords> records."; $Translation["failed"] = "Failed"; $Translation["ok"] = "Ok"; $Translation["mysql said"] = "MySQL said:"; $Translation["table uptodate"] = "Table is up-to-date."; $Translation["couldnt count"] = "Couldn't count records of table <b><TableName></b>"; $Translation["creating table"] = "Creating table <b><TableName></b> ... "; // general config // DO NOT TRANSLATE THE FOLLOWING $Translation["ImageFolder"] = "./images/"; ?> <?php system.php THE FILE TO INCORPORATE INTO THE ABOVE FILE // PLEASE AMEND THE CODE BELOW WITH YOUR DETAILS FOR YOUR SERVERS DATABASE $localhost = "localhost"; // YOUR LOCAL HOST, USUALLY localhost $dbuser = ""; // YOUR DATABASE USERNAME $dbpass = ""; // YOUR DATABASE PASSWORD $dbtable = "";// THE NAME OF YOUR DATABASE , THIS SHOULD HAVE BEEN SET WHEN YOU INSTALLED dbuserdb.sql, SO YOU CAN LEAVE THIS // PLEASE AMEND THE CODE BELOW WITH YOUR URL & FOLDER DETAILS $site_url = "http://www.your website"; // CHANGE THIS TO YOUR OWN WEBSITE URL Ie.(http://www.mysite.com) $site_folder = "index.php"; // WHERE YOUR AGTC CLICK COUNTER FOLDER IS (/myfolder/membershipscript/) $sendersName = "My Website Title"; // // YOU DO NOT NEED TO EDIT BELOW THIS LINE $con = mysql_connect("$localhost","$dbuser","$dbpass") or die("Error Could not connect"); $db = mysql_select_db("$dbtable", $con) or die("Error Could not select database"); ?> Link to comment https://forums.phpfreaks.com/topic/146036-merging-a-configphp-with-anther-configphp-file/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.