filling in the variables of a php file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Patriot
Forum Commoner
Posts: 34
Joined: Tue Jun 18, 2002 1:36 pm

filling in the variables of a php file

Post 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.
User avatar
PaTTeR
Forum Commoner
Posts: 56
Joined: Wed Jul 10, 2002 7:39 am
Location: Bulgaria
Contact:

Post 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);
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post 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);
Post Reply