Code2Design.com

User login

The Layout

Programming

Graphic Design

Resources

Navigation

C2D Projects

Unsystematic Affiliates

Pixel Designz AK Pro Fresh Tuts Project 62 

Change Language

Who's online

There are currently 0 users and 4 guests online.

Writing a PHP Install File

Hey,

I never thought I would be asking for help, but I just need a little wisdom. OK, I'm co-developing this CMS Like software called myHome, and I need to write a file that will on upload of files via FTP, it will go to install.php (The install file I'm trying to create). It doesn't use any Databases or anything YET, so that is good; All I need it to do is create the initiate password and user name for the Admin Control Panel, and write the site URL, site email and other basic information to the config.php file. Should I use the include function or the fwrite to external fire function? Are there any alternatives? How would I have the user input the information into a field, click submit, like the password, site email, etc, and then have that write to the config.php file? I want the installer to be similar to a phpBB Forum (Or any other forum installer) Installer File, where the user inputs information and it gets written to the file. Any help is appreciated!

Thanks
- kab012345


Submitted by kab012345 on January 12, 2008 - 2:59am.
printer friendly version

CMS install file

Well, building a CMS is a great learning experiance. However, I have spent the past year building a new CMS/Framework that can render pages within .004 of a second and has all the features someone could need. So if you wait to wait another month you can download it ;P

Anyway, here is how you would make a install file. You can also download phpBB and look at their install file.

<?php
/*
If someone pressed the "submit" button
(which can only happen if they have seen and filled out the form!)
*/
if(isset($_POST['submit'])) {

   
// Put the $_POST/form data into the file text
   
$text '<?php'"\n".
           
'$db_name = "'$_POST['db_name']. '";'"\n".
           
'$db_user = "'$_POST['db_user']. '";'"\n".
           
'$db_pass = "'$_POST['db_pass']. '";'"\n".
           
'$db_host = "'$_POST['db_host']. '";'"\n".
           
'$admin_name = "'$_POST['admin_name']. '";'"\n".
           
'$admin_pass = "'$_POST['admin_pass']. '";'"\n".
            '
?>
';


// 1) Store the file name in a string (this is the file handle).
$filename = "config.php";
// 2) Open the file
$filehandle = fopen($filename, 'w')
// 3) Write the text above to the file
fwrite($filehandle, $text);
// 4) Close the file handle
fclose($filehandle);

//Now you have a file called "config.php" in the same place as the install.php file.
}
?>


Please Enter your Site Information:
<form action="" method="post">
Database Name: <input name="db_name" type="text" value=""><br />
Database User: <input name="db_user" type="text" value=""><br />
Database Pass: <input name="db_pass" type="text" value=""><br />
Database Host: <input name="db_host" type="text" value="localhost"><br />
<br />
Admin Name: <input name="admin_name" type="text" value=""><br />
Admin Pass: <input name="admin_pass" type="text" value=""><br />

<input name="submit" type="submit" value="Submit">
</form>


Thanks. This helps alot.

Thanks. This helps alot.


One more question

How can we make this installer to write the MySQL tables strait into the database?

Kab and I are trying to make our own forum I can write the SQL but cannot get it go into the database without manualy doing so.


Get a good foundation

It sounds like you should learn how to use PHP and MySQL before you try to write a forum. http://php.net/mysql


Thanks

I know the PHP needed, I just don't know that one bit I looked on that site too >


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br> <br /> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use BBCode tags in the text, URLs will be automatically converted to links
More information about formatting options



Like what you see?

Why not add more? C2D is looking for other Christian Web Masters who would like to help write articles for this site. If you have expericance in FLASH, CSS/HTML, PHP/MySQL, PhotoShop/GIMP, Blender, Javascript, or just General Design - our users would love to hear what you have to say. Contact Us

delicious   digg   reddit   magnoliacom   newsvine   furl   google   yahoo   technorati