form to php file without database

Hey guys, I want to make a page to edit the config.php file. Basically think vBull’s install page, but to edit my config.php file.

Config.php
[php]
$hostname="Host "; //leave as is(most cases)
$user=“Username”; //change to your username
$pass=“Password”; //change to your pass
$db=“Database”; //change to your db name
$main_content=“Welcome to your new portal. You can edit this page through your admin pannel.”;

$admin_username=“Admin Username”; //change to your admin username
$admin_pass=“Admin Pass”; //change to your admin password
[/php]

Sorry, I’m trying to figure out how to word it.

Without using a database (I want to be able to install this portal on any website I make without having to go in and edit the config file with an editor), how can I make a page that will edit this file for me based on what I type into the form? Like Database Name: <input type=text name=db> will write the value for $db. When the config file is called, it’s going to connect to the db and whatnot. The last two lines of the code set the username and password for the adminCP. I saw vBulletin’s install page and got inspired to try to make a page like that, but it failed miserably. Any help would be greatly appreciated!

Use fopen to open and read append the file config.php search[php] $ndb = preg_match(’/Database/’); [/php] ?
Then do something like
[php] $ndb = str_replace( ‘Database’, $_post[‘db’], $ndb );[/php]
on password field I guess, but how will you know what there password and username or will these be set with your own var like %DB% ?

Then post the new content to be entered in where the preg_match found what you were looking for.

write it back to the file and close

User and pass is what they’ll enter for their db. Basically if the database exists it will be the username and password of the mySQL user that can write to the database. They fill in their own with the text fields. Admin user and admin pass will be their username and password for the web portal, which they are setting up.

Thanks for the reply!

I was talking about is this a fresh setup withthere already be a username an password in the config file ?
Or will it be new and you put your own identifier in there to be changed ?

so
[php]$user = ‘CHANGE_USER’;
$pass = ‘CHANGE_PASSWORD’;[/php]

Or will it be already assigned then you post from your script to change it ?

[php]$user = ‘charlies’;
$pass = ‘mixed_char_password’;[/php]

It’ll be a fresh setup, so they’ll enter the information from their phpMyAdmin. It’ll be initially blank in the config file and they’ll “log in” to the database through this form which will be called in almost all the files… So it’ll be new with my own identifiers to be changed

well I am not going to write the code for you so come back with atleast some code of how to open a file and maybe read from it.

look at php functions fopen and fread

Here’s what I have so far… I don’t think I’m understanding how the fwrite works…

changeconfig.php
[php]

<? if (!$action) { ?>

Please configure your new website!.

Hostname:
Username: (Username for host)
Password: (Password for host)
Database: (Database for website)
Admin Username: (Becomes admin username for website)
Admin Password: (Becomes admin password for website)
<?php } else { $nh = $_post['nhost']; $nh = preg_match('/CHANGE_HOSTNAME/'); $nh = str_replace( 'CHANGE_HOSTNAME', $_post['nhost'], $nh ); $nu = $_post['pusername']; $nu = preg_match('/CHANGE_USERNAME/'); $nu = str_replace( 'CHANGE_USERNAME', $_post['pusername'], $nu ); $np = $_post['ppassword']; $np = preg_match('/CHANGE_PASSWORD/'); $np = str_replace( 'CHANGE_PASSWORD', $_post['ppassword'], $np ); $ndb = $_post['db']; $ndb = preg_match('/CHANGE_DATABASE/'); $ndb = str_replace( 'CHANGE_DATABASE', $_post['db'], $ndb ); $nau = $_post['au2']; $nau = preg_match('/CHANGE_AdminUser/'); $nau = str_replace( 'CHANGE_AdminUser', $_post['au2'], $nau ); $nap = $_post['ap2']; $nap = preg_match('/CHANGE_AdminPass/'); $nap = str_replace( 'CHANGE_AdminPass', $_post['ap2'], $nap );

$file = fopen(‘config2.php’, ‘r+’);
fwrite(’$file’, ‘$changeconfig’);
fclose($file);
}

[/php]

When I click submit I run into two errors: (of course I am taking out the full path and giving relative on here)

Warning: preg_match() expects at least 2 parameters, 1 given in ..\maralport\admin\changeconfig.php on line 21,24,27,30,33,36

and

Warning: fwrite(): supplied argument is not a valid stream resource in ..\maralport\admin\changeconfig.php on line 40

Haha sorry if I sound like I want you to write it for me, that’s really not the case. I’m just trying to learn lol

try something like this you will have to add your own error checks to see if things are sent correcly

[php]<?php
if (!isset($_POST[‘Submit’])){
?>
Please configure your new website!.

Hostname:
Username: (Username for host)
Password: (Password for host)
Database: (Database for website)
Admin Username: (Becomes admin username for website)
Admin Password: (Becomes admin password for website)
<?php } if (isset($_POST['Submit'])){ $content = '<?php ' .'$hostname = "'.$_POST['nhost'].'"; ' .'$username =" '.$_POST['pusername'].'"; ' .'$password =" '.$_POST['ppassword'].'"; ' .'$db = "'.$_POST['db'].'"; ' .'$ausername = "'.$_POST['au2'].'"; ' .'$apassword = "'.$_POST['ap2'].'"; ' .'?>';

if(file_exists(‘config2.php’)){
$file = fopen(‘config2.php’, ‘w’);
fwrite($file, $content);
fclose($file);
}
echo ‘config set correctly’;
}
?>[/php]

Genius! Lol thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service