Page 1 of 1
filling in the variables of a php file
Posted: Mon Jul 15, 2002 8:48 pm
by Patriot
how can i fill in the variables of a php file?
like if i wanted someone to edit their config.php file without actually having to open it, rather than just going to install.php and filling in a form.
postnuke has something similar to this, i think.
mostly the variables i would want filled in would be the mysql stuff, (localhost, user, password, etc...)

note: this has to be permanent, the variables cant be passed through different pages after its installed.
Posted: Tue Jul 16, 2002 4:39 am
by PaTTeR
It's very easy if you use
parse_ini_file().
see
http://www.php.net/manual/en/function.p ... i-file.php
You can write something like this:
Code: Select all
$config = parse_ini_file('config.ini',TRUE);
// edit or do somtehing with array $config
$conf_file = fopen('config.ini',"w+");
// for every section in your config
fwrite ($conf_file, ";Some remark\n\n");
fwrite ($conf_file, "їsection]\n\n");
while (list ($key,$value) = each ($configї'section']))
{
fwrite ($conf_file, "$key = $value\n");
}
fclose($conf_file);
Posted: Tue Jul 16, 2002 6:25 am
by jason
You can use the ini file method, or you can simply do what Postnuke does, and that is actually write a PHP file.
Code: Select all
$conf_file = fopen('config.php',"w+");
// for every section in your config
fwrite ($conf_file, '// CONFIG FILE BEING WRITTEN'."\n");
fwrite ($conf_file, '//*************************//'."\n");
fwrite ($conf_file, '$variableToWrite = "'.$_POSTї'valueFromForm'].'";'."\n"
fwrite ($conf_file, '$variableToWrite = "'.$_POSTї'valueFromForm'].'";'."\n"
fwrite ($conf_file, '$variableToWrite = "'.$_POSTї'valueFromForm'].'";'."\n"
fwrite ($conf_file, '$variableToWrite = "'.$_POSTї'valueFromForm'].'";'."\n"
fclose($conf_file);